Skip to content

Commit

Permalink
Merge pull request #200 from ate47/dev_quads
Browse files Browse the repository at this point in the history
Fix some quad issues with some tests
  • Loading branch information
D063520 authored Sep 15, 2023
2 parents 8a73fcd + 2cce19c commit aedace3
Show file tree
Hide file tree
Showing 9 changed files with 308 additions and 21 deletions.
7 changes: 7 additions & 0 deletions hdt-api/src/main/java/org/rdfhdt/hdt/quad/QuadString.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public void clear() {
@Override
public boolean equals(Object other) {
if (!(other instanceof QuadString)) {
if (context.length() == 0) {
// not a quad string, maybe it is a TripleString
return super.equals(other);
}
return false;
}
QuadString qs = (QuadString) other;
Expand Down Expand Up @@ -116,6 +120,9 @@ public QuadString tripleToString() {

@Override
public String toString() {
if (context.length() == 0) {
return super.toString();
}
return super.toString() + " " + context;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,21 @@ public void reorganize(TempTriples triples) {
mapPred.setNewID(j, this.stringToId(mapPred.getString(j), TripleComponentRole.PREDICATE));
}

for(long j=0;j<mapGraph.size();j++) {
mapGraph.setNewID(j, this.stringToId(mapGraph.getString(j), TripleComponentRole.GRAPH));
}

for(long j=0;j<mapObj.size();j++) {
mapObj.setNewID(j, this.stringToId(mapObj.getString(j), TripleComponentRole.OBJECT));
}

for(long j=0;j<mapGraph.size();j++) {
CharSequence str = mapGraph.getString(j);
// check that because stringToId returns 0 for empty strings and if a string is empty its id is
// 0 no matter what
if (str.length() == 0) {
mapGraph.setNewID(j, 1);
} else {
mapGraph.setNewID(j, this.stringToId(str, TripleComponentRole.GRAPH));
}
}

// Replace old IDs with news
triples.replaceAllIds(mapSubj, mapPred, mapObj, mapGraph);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ public void processTriple(TripleString triple, long pos) {
if (dict.supportGraphs()) {
long g = dict.insert(triple.getGraph(), TripleComponentRole.GRAPH);
triples.insert(s, p, o, g);
size+=triple.getSubject().length()+triple.getPredicate().length()+triple.getObject().length()+triple.getGraph().length()+5;
} else {
triples.insert(s, p, o);
size+=triple.getSubject().length()+triple.getPredicate().length()+triple.getObject().length()+triple.getGraph().length()+4; // Spaces and final dot
}
num++;
size+=triple.getSubject().length()+triple.getPredicate().length()+triple.getObject().length()+triple.getGraph().length()+4; // Spaces and final dot
ListenerUtil.notifyCond(listener, "Loaded "+num+" triples", num, 0, 100);
}
}
Expand Down Expand Up @@ -122,13 +123,23 @@ public TempHDT loadFromTriples(HDTOptions specs, Iterator<TripleString> iterator
long size=0;
while(iterator.hasNext()) {
TripleString triple = iterator.next();
triples.insert(
dictionary.insert(triple.getSubject(), TripleComponentRole.SUBJECT),
dictionary.insert(triple.getPredicate(), TripleComponentRole.PREDICATE),
dictionary.insert(triple.getObject(), TripleComponentRole.OBJECT)
);
if (dictionary.supportGraphs()) {
triples.insert(
dictionary.insert(triple.getSubject(), TripleComponentRole.SUBJECT),
dictionary.insert(triple.getPredicate(), TripleComponentRole.PREDICATE),
dictionary.insert(triple.getObject(), TripleComponentRole.OBJECT),
dictionary.insert(triple.getGraph(), TripleComponentRole.GRAPH)
);
size+=triple.getSubject().length()+triple.getPredicate().length()+triple.getObject().length()+triple.getGraph().length()+5; // Spaces and final dot
} else {
triples.insert(
dictionary.insert(triple.getSubject(), TripleComponentRole.SUBJECT),
dictionary.insert(triple.getPredicate(), TripleComponentRole.PREDICATE),
dictionary.insert(triple.getObject(), TripleComponentRole.OBJECT)
);
size+=triple.getSubject().length()+triple.getPredicate().length()+triple.getObject().length()+4; // Spaces and final dot
}
num++;
size+=triple.getSubject().length()+triple.getPredicate().length()+triple.getObject().length()+4; // Spaces and final dot
ListenerUtil.notifyCond(listener, "Loaded "+num+" triples", num, 0, 100);
}
dictionary.endProcessing();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class BitmapQuadsIteratorG extends BitmapTriplesIterator {

// resolves ???G, S??G, SP?G, SPOG queries

private Bitmap bitmapGraph; // the graph bitmap for the search
private final Bitmap bitmapGraph; // the graph bitmap for the search

public BitmapQuadsIteratorG(BitmapTriples triples, TripleID pattern) {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.jena.datatypes.xsd.impl.RDFLangString;
import org.apache.jena.graph.Node;
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.sparql.core.Quad;

/**
* Converts a Jena {@link Node} to a String format that will round trip back to the same Node via
Expand All @@ -42,7 +43,7 @@ public static String format(RDFNode n) {
}

public static String format(Node node) {
if (node == null) {
if (node == null || Quad.isDefaultGraph(node)) {
return "";
}
if (node.isURI()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ public void replaceAllIds(
(int)mapGraph.getNewID(triple.getGraph() -1)
);
} else {
throw new RuntimeException("You must call the replaceAllIds method without a DictionaryIDMapping for graphs if the triples are not quads.");
throw new IllegalArgumentException("You must call the replaceAllIds method without a DictionaryIDMapping for graphs if the triples are not quads.");
}
}
}
Expand All @@ -550,7 +550,7 @@ public void replaceAllIds(
sorted=false;
for(TripleIDInt triple : arrayOfTriples) {
if (triple.isQuad()) {
throw new RuntimeException("You must call the replaceAllIds method with a DictionaryIDMapping for graphs if the triples are quads.");
throw new IllegalArgumentException("You must call the replaceAllIds method with a DictionaryIDMapping for graphs if the triples are quads.");
} else {
triple.setAll(
(int)mapSubj.getNewID(triple.getSubject() -1),
Expand Down
Loading

0 comments on commit aedace3

Please sign in to comment.