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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
quad patterns support (not implemented yet)
  • Loading branch information
QuentinJanuel committed Jun 15, 2023
commit 7a024f5dcbb2c6f7383188fd2b3572b8711f9de2
79 changes: 63 additions & 16 deletions hdt-java-cli/src/main/java/org/rdfhdt/hdt/tools/HdtSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@
import java.util.ArrayList;
import java.util.List;

import org.rdfhdt.hdt.dictionary.Dictionary;
import org.rdfhdt.hdt.dictionary.DictionarySection;
import org.rdfhdt.hdt.exceptions.NotFoundException;
import org.rdfhdt.hdt.exceptions.ParserException;
import org.rdfhdt.hdt.hdt.HDT;
import org.rdfhdt.hdt.hdt.HDTManager;
import org.rdfhdt.hdt.hdt.HDTVersion;
import org.rdfhdt.hdt.listener.ProgressListener;
import org.rdfhdt.hdt.options.HDTOptions;
import org.rdfhdt.hdt.quad.QuadString;
import org.rdfhdt.hdt.triples.IteratorTripleString;
import org.rdfhdt.hdt.triples.TripleString;
import org.rdfhdt.hdt.util.StopWatch;
Expand Down Expand Up @@ -79,7 +82,14 @@ public class HdtSearch {
@Parameter(names = "-memory", description = "Load the whole file into main memory. Ensures fastest querying.")
public boolean loadInMemory;

protected static void iterate(HDT hdt, CharSequence subject, CharSequence predicate, CharSequence object) throws NotFoundException {
protected static void iterate(
HDT hdt,
boolean isHDTQ,
CharSequence subject,
CharSequence predicate,
CharSequence object,
CharSequence graph
) throws NotFoundException {
StopWatch iterateTime = new StopWatch();
int count;

Expand Down Expand Up @@ -118,34 +128,58 @@ private void help() {
* Read from a line, where each component is separated by space.
* @param line line to parse
*/
private static void parseTriplePattern(TripleString dest, String line) throws ParserException {
private static void parseTriplePattern(QuadString dest, String line, boolean isHDTQ) throws ParserException {
int split, posa, posb;
ParserException ex = new ParserException(
QuentinJanuel marked this conversation as resolved.
Show resolved Hide resolved
isHDTQ
? "Make sure that you included four terms."
: "Make sure that you included three terms."
); // Not found, error.
dest.clear();

// SET SUBJECT
posa = 0;
posb = split = line.indexOf(' ', posa);

if(posb==-1) throw new ParserException("Make sure that you included three terms."); // Not found, error.
if(posb==-1) throw ex;

dest.setSubject(UnicodeEscape.unescapeString(line.substring(posa, posb)));

// SET PREDICATE
posa = split+1;
posb = split = line.indexOf(' ', posa);

if(posb==-1) throw new ParserException("Make sure that you included three terms.");
if(posb==-1) throw ex;

dest.setPredicate(UnicodeEscape.unescapeString(line.substring(posa, posb)));

// SET OBJECT
posa = split+1;
posb = line.length();

if(line.charAt(posb-1)=='.') posb--; // Remove trailing <space> <dot> from NTRIPLES.
if(line.charAt(posb-1)==' ') posb--;

dest.setObject(UnicodeEscape.unescapeString(line.substring(posa, posb)));
if (isHDTQ) {
// SET OBJECT
posa = split+1;
posb = split = line.indexOf(' ', posa);

if(posb==-1) throw ex;

dest.setObject(UnicodeEscape.unescapeString(line.substring(posa, posb)));

// SET GRAPH
posa = split+1;
posb = line.length();

if(line.charAt(posb-1)=='.') posb--;
if(line.charAt(posb-1)==' ') posb--;

dest.setGraph(UnicodeEscape.unescapeString(line.substring(posa, posb)));
} else {
// SET OBJECT
posa = split+1;
posb = line.length();

if(line.charAt(posb-1)=='.') posb--; // Remove trailing <space> <dot> from NTRIPLES.
if(line.charAt(posb-1)==' ') posb--;

dest.setObject(UnicodeEscape.unescapeString(line.substring(posa, posb)));
}
}

public void execute() throws IOException {
Expand All @@ -169,10 +203,12 @@ public void execute() throws IOException {
} else {
hdt= HDTManager.mapIndexedHDT(hdtInput, spec, listenerConsole);
}
Dictionary dict = hdt.getDictionary();
boolean isHDTQ = dict.supportGraphs();

BufferedReader in = new BufferedReader(new InputStreamReader(System.in, UTF_8));
try {
TripleString triplePattern = new TripleString();
QuadString triplePattern = new QuadString();

while(true) {
System.out.print(">> ");
Expand All @@ -187,10 +223,21 @@ public void execute() throws IOException {
}

try {
parseTriplePattern(triplePattern, line);
System.out.println("Query: |"+triplePattern.getSubject()+"| |"+triplePattern.getPredicate()+"| |" + triplePattern.getObject()+"|");
parseTriplePattern(triplePattern, line, isHDTQ);
if (isHDTQ) {
System.out.println("Query: |"+triplePattern.getSubject()+"| |"+triplePattern.getPredicate()+"| |" + triplePattern.getObject()+"| |" + triplePattern.getGraph()+"|");
} else {
System.out.println("Query: |"+triplePattern.getSubject()+"| |"+triplePattern.getPredicate()+"| |" + triplePattern.getObject()+"|");
}

iterate(hdt,triplePattern.getSubject(),triplePattern.getPredicate(),triplePattern.getObject());
iterate(
hdt,
isHDTQ,
triplePattern.getSubject(),
triplePattern.getPredicate(),
triplePattern.getObject(),
triplePattern.getGraph()
);
} catch (ParserException e) {
System.err.println("Could not parse triple pattern: "+e.getMessage());
help();
Expand Down