Skip to content
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

Adding support for named graphs #196

Merged
merged 32 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f69df74
Implemented quad dictionaries for .nq files
QuentinJanuel May 31, 2023
728446d
temp triples can handle quads
QuentinJanuel Jun 1, 2023
3d9e29a
making sure graphs don't affect normal hdt
QuentinJanuel Jun 5, 2023
9a7d09d
FourQuadSectionDictionary needs to implement FourSectionDictionary, n…
QuentinJanuel Jun 15, 2023
7a024f5
quad patterns support (not implemented yet)
QuentinJanuel Jun 15, 2023
82cb465
fixed quadstring
QuentinJanuel Jun 22, 2023
3439c49
save triples (could be optimized)
QuentinJanuel Jun 22, 2023
a4f5bfb
search wip
QuentinJanuel Jun 26, 2023
d672ee9
Fixed search for triples (non quad)
QuentinJanuel Jun 29, 2023
c26b85e
number of graphs is now dynamic
QuentinJanuel Jun 29, 2023
f58cfa6
Adapt code for large files (RoaringBitmap)
QuentinJanuel Jul 11, 2023
bcc095a
roaring bitmap 64
QuentinJanuel Jul 13, 2023
f45facb
accelerated wildcard pattern a bit
QuentinJanuel Jul 13, 2023
1e612c3
BitmapQuadsIterator
QuentinJanuel Jul 17, 2023
8d31b3d
fixed roaring bitmap
QuentinJanuel Jul 20, 2023
c8b0c1e
let quads iterator variables be longs
QuentinJanuel Jul 20, 2023
b1ba3a6
support for ???G, S??G, SP?G & SPOG
QuentinJanuel Jul 20, 2023
0f1685b
?POG & ??OG (ZGFOQ)
QuentinJanuel Jul 28, 2023
5ccc86b
removed forgotten log
QuentinJanuel Jul 28, 2023
257aa30
?PO? & ??O? (ZFOQ)
QuentinJanuel Jul 28, 2023
76ee129
?P?G (YGFOQ)
QuentinJanuel Jul 31, 2023
41abd02
?P?? (YFOQ)
QuentinJanuel Aug 4, 2023
cbfeedc
address https://github.com/rdfhdt/hdt-java/pull/196#discussion_r12416…
QuentinJanuel Aug 28, 2023
b9002a6
address https://github.com/rdfhdt/hdt-java/pull/196#discussion_r12955…
QuentinJanuel Aug 28, 2023
fef55fb
address https://github.com/rdfhdt/hdt-java/pull/196#discussion_r12955…
QuentinJanuel Aug 28, 2023
5233663
address https://github.com/rdfhdt/hdt-java/pull/196#discussion_r12955…
QuentinJanuel Aug 28, 2023
59bba7c
address https://github.com/rdfhdt/hdt-java/pull/196#discussion_r12955…
QuentinJanuel Aug 28, 2023
7ae491c
address https://github.com/rdfhdt/hdt-java/pull/196#discussion_r12958…
QuentinJanuel Aug 28, 2023
eacd5bb
address https://github.com/rdfhdt/hdt-java/pull/196#discussion_r12958…
QuentinJanuel Aug 28, 2023
f61bc58
address https://github.com/rdfhdt/hdt-java/pull/196#discussion_r12959…
QuentinJanuel Aug 31, 2023
c675a01
cat tests for quads
QuentinJanuel Sep 4, 2023
3f4ba41
test quads iterators
QuentinJanuel Sep 5, 2023
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
13 changes: 13 additions & 0 deletions hdt-api/src/main/java/org/rdfhdt/hdt/dictionary/Dictionary.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ public interface Dictionary extends Closeable {
*/
long getNobjects();

/**
* Returns the number of objects in the dictionary. Note: Includes shared
*/
long getNgraphs();

/**
* Returns the number of subjects/objects in the dictionary.
*/
Expand All @@ -111,6 +116,8 @@ public interface Dictionary extends Closeable {

DictionarySection getObjects();

DictionarySection getGraphs();

Map<? extends CharSequence, DictionarySection> getAllObjects();

DictionarySection getShared();
Expand All @@ -125,4 +132,10 @@ public interface Dictionary extends Closeable {
* @return type
*/
String getType();

/**
* Returns whether the dictionary supports graphs
* @return true if it supports graphs, false otherwise
*/
boolean supportGraphs();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ public enum DictionarySectionRole {
SUBJECT,
PREDICATE,
OBJECT,
SHARED
SHARED,
GRAPH,
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ public enum TripleComponentRole {
PREDICATE,
/** The triple is an object */
OBJECT,
/** The triple is a graph */
GRAPH,
}
2 changes: 2 additions & 0 deletions hdt-api/src/main/java/org/rdfhdt/hdt/hdt/HDTVocabulary.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public class HDTVocabulary {
public static final String DICTIONARY_TYPE_PLAIN = HDT_DICTIONARY_BASE+"Plain>";
public static final String DICTIONARY_TYPE_FOUR_SECTION = HDT_DICTIONARY_BASE+"Four>";
public static final String DICTIONARY_TYPE_MULT_SECTION = HDT_DICTIONARY_BASE+"Mult>";
public static final String DICTIONARY_TYPE_FOUR_QUAD_SECTION = HDT_DICTIONARY_BASE+"FourQuad>";

public static final String DICTIONARY_TYPE_FOUR_PSFC_SECTION = HDT_DICTIONARY_BASE+"FourPsfc>";

Expand All @@ -106,6 +107,7 @@ public class HDTVocabulary {
public static final String TRIPLES_TYPE_PLAIN = HDT_TRIPLES_BASE+"Plain>";
public static final String TRIPLES_TYPE_COMPACT = HDT_TRIPLES_BASE+"Compact>";
public static final String TRIPLES_TYPE_BITMAP = HDT_TRIPLES_BASE+"Bitmap>";
public static final String TRIPLES_TYPE_BITMAP_QUAD = HDT_TRIPLES_BASE+"BitmapQuad>";

// Index type
public static final String INDEX_TYPE_FOQ = HDT_BASE+"indexFoQ>";
Expand Down
11 changes: 10 additions & 1 deletion hdt-api/src/main/java/org/rdfhdt/hdt/options/HDTOptionsKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ public class HDTOptionsKeys {
*/
@Value(key = TEMP_DICTIONARY_IMPL_KEY, desc = "hash dictionary")
public static final String TEMP_DICTIONARY_IMPL_VALUE_HASH = "hash";
/**
* use Hash quad to create the HDTQ
*/
public static final String TEMP_DICTIONARY_IMPL_VALUE_HASH_QUAD = "hashQuad";
/**
* use Hash map to create the HDT and store the multisection dictionary, mandatory to create MSC
*/
Expand All @@ -282,8 +286,13 @@ public class HDTOptionsKeys {
/**
* 4 Section dictionary
*/
@Value(key = DICTIONARY_TYPE_KEY, desc = "Four sectiob dictionary")
@Value(key = DICTIONARY_TYPE_KEY, desc = "Four section dictionary")
public static final String DICTIONARY_TYPE_VALUE_FOUR_SECTION = HDTVocabulary.DICTIONARY_TYPE_FOUR_SECTION;
/*
* 4 Quad Section dictionary
*/
@Value(key = DICTIONARY_TYPE_KEY, desc = "Four quad section dictionary")
public static final String DICTIONARY_TYPE_VALUE_FOUR_QUAD_SECTION = HDTVocabulary.DICTIONARY_TYPE_FOUR_QUAD_SECTION;
/**
* Prefix AND Suffix front-coded (PSFC) 4 Section dictionary
*/
Expand Down
10 changes: 6 additions & 4 deletions hdt-api/src/main/java/org/rdfhdt/hdt/quad/QuadString.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public QuadString(CharSequence subject, CharSequence predicate, CharSequence obj

public QuadString(TripleString other) {
super(other);
this.context = other.getObject();
this.context = other.getGraph();
}

@Override
Expand All @@ -29,9 +29,6 @@ public void clear() {

@Override
public boolean equals(Object other) {
if (context.length() == 0) {
return super.equals(other);
}
if (!(other instanceof QuadString)) {
return false;
}
Expand Down Expand Up @@ -116,4 +113,9 @@ public int hashCode() {
public QuadString tripleToString() {
return new QuadString(subject.toString(), predicate.toString(), object.toString(), context.toString());
}

@Override
public String toString() {
return super.toString() + " " + context;
}
}
24 changes: 24 additions & 0 deletions hdt-api/src/main/java/org/rdfhdt/hdt/rdf/RDFAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,28 @@ public interface RDFAccess {
* @throws NotFoundException when the triple cannot be found
*/
IteratorTripleString search(CharSequence subject, CharSequence predicate, CharSequence object) throws NotFoundException;

/**
* Iterate over the triples of an RDF Set that match the specified pattern.
* null and empty strings act as a wildcard.
* (e.g. search(null, null, null, null) iterates over all elements)
*
* @param subject
* The subject to search
* @param predicate
* The predicate to search
* @param object
* The object to search
* @param graph
* The graph to search
*
* @return Iterator of TripleStrings
* @throws NotFoundException when the triple cannot be found
*/
IteratorTripleString search(
CharSequence subject,
CharSequence predicate,
CharSequence object,
CharSequence graph
) throws NotFoundException;
}
86 changes: 77 additions & 9 deletions hdt-api/src/main/java/org/rdfhdt/hdt/triples/TripleID.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public final class TripleID implements Comparable<TripleID>, Serializable, Clone
private long subject;
private long predicate;
private long object;
private long graph;
private boolean isQuad = false;

/**
* Basic constructor
Expand All @@ -68,6 +70,27 @@ public TripleID(long subject, long predicate, long object) {
this.object = object;
}

/**
* Constructor
*
* @param subject
* The subject
* @param predicate
* The predicate
* @param object
* The object
* @param graph
* The graph
*/
public TripleID(long subject, long predicate, long object, long graph) {
super();
this.subject = subject;
this.predicate = predicate;
this.object = object;
this.graph = graph;
this.isQuad = true;
}

/**
* Build a TripleID as a copy of another one.
* @param other the triple ID to copy
Expand All @@ -77,6 +100,12 @@ public TripleID(TripleID other) {
this.subject = other.subject;
this.predicate = other.predicate;
this.object = other.object;
this.graph = other.graph;
this.isQuad = other.isQuad;
}

public boolean isQuad() {
return isQuad;
}

/**
Expand Down Expand Up @@ -124,6 +153,22 @@ public void setPredicate(long predicate) {
this.predicate = predicate;
}

/**
* @return long the graph
*/
public long getGraph() {
return graph;
}

/**
* @param graph
* the graph to set
*/
public void setGraph(long graph) {
this.graph = graph;
this.isQuad = true;
}

/**
* Replace all components of a TripleID at once. Useful to reuse existing objects.
* @param subject subject ID
Expand All @@ -136,17 +181,35 @@ public void setAll(long subject, long predicate, long object) {
this.object = object;
}

/**
* Replace all components of a TripleID at once. Useful to reuse existing objects.
* @param subject subject ID
* @param predicate predicate ID
* @param object object ID
* @param graph graph ID
*/
public void setAll(long subject, long predicate, long object, long graph) {
this.subject = subject;
this.predicate = predicate;
this.object = object;
this.graph = graph;
this.isQuad = true;
}

public void assign(TripleID replacement) {
subject = replacement.getSubject();
object = replacement.getObject();
predicate = replacement.getPredicate();
graph = replacement.getGraph();
isQuad = replacement.isQuad();
}

/**
* Set all components to zero.
*/
public void clear() {
subject = predicate = object = 0;
subject = predicate = object = graph = 0;
isQuad = false;
}

/*
Expand All @@ -156,6 +219,8 @@ public void clear() {
*/
@Override
public String toString() {
if (isQuad)
return subject + " " + predicate + " " + object + " " + graph;
return subject + " " + predicate + " " + object;
}

Expand Down Expand Up @@ -192,11 +257,13 @@ public boolean match(TripleID pattern) {
long subjectPattern = pattern.getSubject();
long predicatePattern = pattern.getPredicate();
long objectPattern = pattern.getObject();
long graphPattern = pattern.getGraph();

/* Remember that 0 acts as a wildcard */
if (subjectPattern == 0 || this.subject == subjectPattern) {
if (predicatePattern == 0 || this.predicate == predicatePattern) {
return objectPattern == 0 || this.object == objectPattern;
if (objectPattern == 0 || this.object == objectPattern) {
return graphPattern == 0 || this.graph == graphPattern;
}
}
}
return false;
Expand All @@ -207,23 +274,23 @@ public boolean match(TripleID pattern) {
* @return boolean
*/
public boolean isEmpty() {
return !(subject != 0 || predicate != 0 || object != 0);
return !(subject != 0 || predicate != 0 || object != 0 || graph != 0);
}

/**
* Check whether none of the components of the triple are empty.
* @return boolean
*/
public boolean isValid() {
return subject>0 && predicate>0 && object>0;
return subject>0 && predicate>0 && object>0 && (isQuad ? graph>0 : true);
}

/**
* Checks whether any of the components of the triple are "no match" (-1).
* @return boolean
*/
public boolean isNoMatch() {
return subject == -1 || predicate == -1 || object == -1;
return subject == -1 || predicate == -1 || object == -1 || graph == -1;
QuentinJanuel marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand All @@ -234,7 +301,8 @@ public String getPatternString() {
return "" +
(subject==0 ? '?' : 'S') +
(predicate==0 ? '?' : 'P') +
(object==0 ? '?' : 'O');
(object==0 ? '?' : 'O') +
(isQuad ? (graph==0 ? '?' : 'G') : "");
}

/**
Expand All @@ -252,7 +320,7 @@ public boolean equals(Object o) {
return false;
}
TripleID other = (TripleID) o;
return !( subject!=other.subject || predicate!=other.predicate || object!=other.object );
return !( subject!=other.subject || predicate!=other.predicate || object!=other.object || graph!=other.graph );
}

@Override
Expand All @@ -266,6 +334,6 @@ public TripleID clone() {

@Override
public int hashCode() {
return (int) (subject * 13 + predicate * 17 + object * 31);
return (int) (subject * 13 + predicate * 17 + object * 31 + graph * 37);
}
}
Loading