Skip to content

Formatting and upgrades #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions nb-configuration.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<netbeans.hint.license>mit</netbeans.hint.license>
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>1.7-web</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>
<org-netbeans-modules-whitelist.whitelist-oracle>false</org-netbeans-modules-whitelist.whitelist-oracle>
</properties>
</project-shared-configuration>
84 changes: 31 additions & 53 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,21 @@
<modelVersion>4.0.0</modelVersion>
<groupId>LDF-Server</groupId>
<artifactId>LDF-Server</artifactId>
<version>0.0.1</version>
<version>0.0.2</version>
<packaging>war</packaging>

<properties>
<jettyVersion>9.2.5.v20141112</jettyVersion>
<jettyVersion>9.3.6.v20151106</jettyVersion>
</properties>

<dependencies>
<dependency>
<groupId>org.rdfhdt</groupId>
<artifactId>hdt-jena</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-core</artifactId>
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-arq</artifactId>
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.5</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jettyVersion}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jettyVersion}</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -104,4 +55,31 @@
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.3.6.v20151106</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.rdfhdt</groupId>
<artifactId>hdt-jena</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.3.6.v20151106</version>
</dependency>
</dependencies>
</project>
13 changes: 6 additions & 7 deletions src/org/linkeddatafragments/config/ConfigReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@
* @author Ruben Verborgh
*/
public class ConfigReader {

private final Map<String, JsonObject> dataSources = new HashMap<String, JsonObject>();
private final Map<String, String> prefixes = new HashMap<String, String>();
private final Map<String, JsonObject> dataSources = new HashMap<>();
private final Map<String, String> prefixes = new HashMap<>();

/**
* Creates a new configuration reader.
*
* @param configReader the configuration
*/
public ConfigReader(Reader configReader) {
final JsonObject root = new JsonParser().parse(configReader).getAsJsonObject();
for (final Entry<String, JsonElement> entry : root.getAsJsonObject("datasources").entrySet()) {
final JsonObject dataSource = entry.getValue().getAsJsonObject();
JsonObject root = new JsonParser().parse(configReader).getAsJsonObject();
for (Entry<String, JsonElement> entry : root.getAsJsonObject("datasources").entrySet()) {
JsonObject dataSource = entry.getValue().getAsJsonObject();
this.dataSources.put(entry.getKey(), dataSource);
}
for (final Entry<String, JsonElement> entry : root.getAsJsonObject("prefixes").entrySet()) {
for (Entry<String, JsonElement> entry : root.getAsJsonObject("prefixes").entrySet()) {
this.prefixes.put(entry.getKey(), entry.getValue().getAsString());
}
}
Expand Down
92 changes: 50 additions & 42 deletions src/org/linkeddatafragments/datasource/HdtDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,53 +49,61 @@ public TriplePatternFragment getFragment(Resource subject, Property predicate, R
throw new IllegalArgumentException("limit");
}

// look up the result from the HDT datasource
final int subjectId = subject == null ? 0 : dictionary.getIntID(subject.asNode(), TripleComponentRole.SUBJECT);
final int predicateId = predicate == null ? 0 : dictionary.getIntID(predicate.asNode(), TripleComponentRole.PREDICATE);
final int objectId = object == null ? 0 : dictionary.getIntID(object.asNode(), TripleComponentRole.OBJECT);
// look up the result from the HDT datasource)
int subjectId = subject == null ? 0 : dictionary.getIntID(subject.asNode(), TripleComponentRole.SUBJECT);
int predicateId = predicate == null ? 0 : dictionary.getIntID(predicate.asNode(), TripleComponentRole.PREDICATE);
int objectId = object == null ? 0 : dictionary.getIntID(object.asNode(), TripleComponentRole.OBJECT);

if (subjectId < 0 || predicateId < 0 || objectId < 0) {
return new TriplePatternFragmentBase();
}

final Model triples = ModelFactory.createDefaultModel();
final IteratorTripleID matches = datasource.getTriples().search(new TripleID(subjectId, predicateId, objectId));
final boolean hasMatches = matches.hasNext();
IteratorTripleID matches = datasource.getTriples().search(new TripleID(subjectId, predicateId, objectId));
boolean hasMatches = matches.hasNext();

if (hasMatches) {
// try to jump directly to the offset
boolean atOffset;
if (matches.canGoTo()) {
try {
matches.goTo(offset);
atOffset = true;
}
// if the offset is outside the bounds, this page has no matches
catch (IndexOutOfBoundsException exception) { atOffset = false; }
}
// if not possible, advance to the offset iteratively
else {
matches.goToStart();
for (int i = 0; !(atOffset = i == offset) && matches.hasNext(); i++)
matches.next();
}
// try to add `limit` triples to the result model
if (atOffset) {
for (int i = 0; i < limit && matches.hasNext(); i++)
triples.add(triples.asStatement(toTriple(matches.next())));
}
}

// estimates can be wrong; ensure 0 is returned if there are no results, and always more than actual results
final long estimatedTotal = triples.size() > 0 ? Math.max(offset + triples.size() + 1, matches.estimatedNumResults())
: hasMatches ? Math.max(matches.estimatedNumResults(), 1) : 0;
if (hasMatches) {
// try to jump directly to the offset
boolean atOffset;
if (matches.canGoTo()) {
try {
matches.goTo(offset);
atOffset = true;
} // if the offset is outside the bounds, this page has no matches
catch (IndexOutOfBoundsException exception) {
atOffset = false;
}
} // if not possible, advance to the offset iteratively
else {
matches.goToStart();
for (int i = 0; !(atOffset = i == offset) && matches.hasNext(); i++) {
matches.next();
}
}
// try to add `limit` triples to the result model
if (atOffset) {
for (int i = 0; i < limit && matches.hasNext(); i++) {
triples.add(triples.asStatement(toTriple(matches.next())));
}
}
}

// estimates can be wrong; ensure 0 is returned if there are no results, and always more than actual results
final long estimatedTotal = triples.size() > 0 ? Math.max(offset + triples.size() + 1, matches.estimatedNumResults())
: hasMatches ? Math.max(matches.estimatedNumResults(), 1) : 0;

// create the fragment
return new TriplePatternFragment() {
@Override
public Model getTriples() { return triples; }

@Override
public long getTotalSize() { return estimatedTotal; }
};
@Override
public Model getTriples() {
return triples;
}

@Override
public long getTotalSize() {
return estimatedTotal;
}
};
}

/**
Expand All @@ -106,9 +114,9 @@ public TriplePatternFragment getFragment(Resource subject, Property predicate, R
*/
private Triple toTriple(TripleID tripleId) {
return new Triple(
dictionary.getNode(tripleId.getSubject(), TripleComponentRole.SUBJECT),
dictionary.getNode(tripleId.getPredicate(), TripleComponentRole.PREDICATE),
dictionary.getNode(tripleId.getObject(), TripleComponentRole.OBJECT)
dictionary.getNode(tripleId.getSubject(), TripleComponentRole.SUBJECT),
dictionary.getNode(tripleId.getPredicate(), TripleComponentRole.PREDICATE),
dictionary.getNode(tripleId.getObject(), TripleComponentRole.OBJECT)
);
}
}
26 changes: 13 additions & 13 deletions src/org/linkeddatafragments/datasource/IDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
* @author Ruben Verborgh
*/
public interface IDataSource {
/**
* Gets a page of the Basic Linked Data Fragment matching the specified triple pattern.
* @param subject the subject (null to match any subject)
* @param predicate the predicate (null to match any predicate)
* @param object the object (null to match any object)
* @param offset the triple index at which to start the page
* @param limit the number of triples on the page
* @return the first page of the fragment
*/
public TriplePatternFragment getFragment(Resource subject, Property predicate, RDFNode object,
long offset, long limit);
public String getTitle();
/**
* Gets a page of the Basic Linked Data Fragment matching the specified triple pattern.
* @param subject the subject (null to match any subject)
* @param predicate the predicate (null to match any predicate)
* @param object the object (null to match any object)
* @param offset the triple index at which to start the page
* @param limit the number of triples on the page
* @return the first page of the fragment
*/
public TriplePatternFragment getFragment(Resource subject, Property predicate,
RDFNode object, long offset, long limit);
public String getTitle();

public String getDescription();
public String getDescription();
}
22 changes: 11 additions & 11 deletions src/org/linkeddatafragments/datasource/TriplePatternFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
* @author Ruben Verborgh
*/
public interface TriplePatternFragment {
/**
* Gets the data of this fragment (possibly only partial).
* @return the data as triples
*/
public Model getTriples();
/**
* Gets the total number of triples in the fragment (can be an estimate).
* @return the total number of triples
*/
public long getTotalSize();
/**
* Gets the data of this fragment (possibly only partial).
* @return the data as triples
*/
public Model getTriples();

/**
* Gets the total number of triples in the fragment (can be an estimate).
* @return the total number of triples
*/
public long getTotalSize();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@
* @author Ruben Verborgh
*/
public class TriplePatternFragmentBase implements TriplePatternFragment {
private final Model triples;
private final long totalSize;

/**
* Creates an empty Basic Linked Data Fragment.
*/
public TriplePatternFragmentBase() {
this(null, 0);
}

/**
* Creates a new Basic Linked Data Fragment.
* @param triples the triples (possibly partial)
* @param totalSize the total size
*/
public TriplePatternFragmentBase(Model triples, long totalSize) {
this.triples = triples == null ? ModelFactory.createDefaultModel() : triples;
this.totalSize = totalSize < 0 ? 0 : totalSize;
}
private final Model triples;
private final long totalSize;

@Override
public Model getTriples() {
return triples;
}
/**
* Creates an empty Basic Linked Data Fragment.
*/
public TriplePatternFragmentBase() {
this(null, 0);
}

@Override
public long getTotalSize() {
return totalSize;
}
/**
* Creates a new Basic Linked Data Fragment.
* @param triples the triples (possibly partial)
* @param totalSize the total size
*/
public TriplePatternFragmentBase(Model triples, long totalSize) {
this.triples = triples == null ? ModelFactory.createDefaultModel() : triples;
this.totalSize = totalSize < 0 ? 0 : totalSize;
}

@Override
public Model getTriples() {
return triples;
}

@Override
public long getTotalSize() {
return totalSize;
}
}
Loading