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 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
?PO? & ??O? (ZFOQ)
  • Loading branch information
QuentinJanuel committed Jul 28, 2023
commit 257aa306f30dce791471de622b00df52e3a31b1d
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
package org.rdfhdt.hdt.quads.impl;

import java.util.List;

import org.rdfhdt.hdt.compact.bitmap.Bitmap;
import org.rdfhdt.hdt.enums.ResultEstimationType;
import org.rdfhdt.hdt.enums.TripleComponentOrder;
import org.rdfhdt.hdt.exceptions.NotImplementedException;
import org.rdfhdt.hdt.triples.TripleID;
import org.rdfhdt.hdt.triples.impl.BitmapTriples;
import org.rdfhdt.hdt.triples.impl.BitmapTriplesIteratorZFOQ;
import org.rdfhdt.hdt.triples.impl.TripleOrderConvert;

public class BitmapQuadsIteratorZFOQ extends BitmapTriplesIteratorZFOQ{

// resolves ?PO?, ??O? queries

private List<Bitmap> bitmapsGraph; // one bitmap per graph
private int numberOfGraphs;
private long posG; // the current graph bitmap
private int g; // g is variable
private boolean updateXYZ = true;

public BitmapQuadsIteratorZFOQ(BitmapTriples triples, TripleID pattern) {
super(triples, pattern);

this.triples = triples;
this.returnTriple = new TripleID();
this.pattern = new TripleID();
this.bitmapsGraph = triples
.getQuadInfoAG();
this.numberOfGraphs = bitmapsGraph.size();
newSearch(pattern);
}

@Override
public void goToStart() {
super.goToStart();
if(hasNext()) {
posG = getNextGraphPosition(0);
}
}

/*
* Get the next solution
*/
@Override
public TripleID next() {
if(updateXYZ) {
long posY = adjIndex.get(posIndex); // get the position of the next occurrence of the predicate in AdjY

z = patZ!=0 ? patZ : (int)adjIndex.findListIndex(posIndex)+1; //get the next object (z) as the number of list in adIndex corresponding to posIndex
y = patY!=0 ? patY : (int) adjY.get(posY); // get the next predicate (y) as the element in adjY stores in position posY
x = (int) adjY.findListIndex(posY)+1; //get the next subject (X) as the number of list in adjY corresponding to posY

updateXYZ = false;
}
g = (int) posG + 1;

posG = getNextGraphPosition((int) posG + 1); // get the next graph position for the current triple
if(posG == numberOfGraphs) { // there are no further graphs for this triple
posIndex++; // increase the position of the next occurrence of the predicate
if(hasNext()) {
updateXYZ = true;
posG = getNextGraphPosition(0);
}
}

updateOutput(); // set the components (subject,predicate,object) of the returned triple
return returnTriple; // return the triple as solution
}

private int getNextGraphPosition(int pos) {
int nextTriplePos = (int) getNextTriplePosition();
while(pos < numberOfGraphs && !bitmapsGraph.get(pos).access(nextTriplePos)) {
pos++;
}
return pos;
}

private long getNextTriplePosition() {
long ret =0;
try {
ret = triples.adjZ.find(adjIndex.get(posIndex),patZ);
} catch (Exception e) {}
return ret;
}

@Override
protected void updateOutput() {
returnTriple.setAll(x, y, z, g);
TripleOrderConvert.swapComponentOrder(returnTriple, triples.order, TripleComponentOrder.SPO);
}

@Override
public ResultEstimationType numResultEstimation() {
return ResultEstimationType.MORE_THAN;
}

private void newSearch(TripleID pattern) {
this.pattern.assign(pattern);

TripleOrderConvert.swapComponentOrder(this.pattern, TripleComponentOrder.SPO, triples.order);
patZ = this.pattern.getObject();
if(patZ==0 && (patY!=0 || this.pattern.getSubject()!=0)) {
throw new IllegalArgumentException("This structure is not meant to process this pattern");
}

patY = this.pattern.getPredicate();

adjY = triples.adjY;
adjIndex = triples.adjIndex; // adjIndex has the list of positions in adY

findRange(); // get the boundaries where the solution for the given object can be found
goToStart(); // load the first solution and position the next pointers
}

private void findRange() {
if(patZ==0) { //if the object is not provided (usually it is in this iterator)
minIndex = 0;
maxIndex = adjIndex.getNumberOfElements();
return;
}
minIndex = adjIndex.find(patZ-1); //find the position of the first occurrence of the object
maxIndex = adjIndex.last(patZ-1); //find the position of the last ocurrence of the object

if(patY!=0) { // if the predicate is provided then we do a binary search to search for such predicate
while (minIndex <= maxIndex) {
long mid = (minIndex + maxIndex) / 2;
long predicate=getY(mid); //get predicate at mid position in the object index

if (patY > predicate) {
minIndex = mid + 1;
} else if (patY < predicate) {
maxIndex = mid - 1;
} else { // the predicate has been found, now we have to find the min and max limits (the predicate P is repeated for each PO occurrence in the triples)
// Binary Search to find left boundary
long left=minIndex;
long right=mid;
long pos=0;

while(left<=right) {
pos = (left+right)/2;

predicate = getY(pos);

if(predicate!=patY) {
left = pos+1;
} else {
right = pos-1;
}
}
minIndex = predicate==patY ? pos : pos+1;

// Binary Search to find right boundary
left = mid;
right= maxIndex;

while(left<=right) {
pos = (left+right)/2;
predicate = getY(pos);

if(predicate!=patY) {
right = pos-1;
} else {
left = pos+1;
}
}
maxIndex = predicate==patY ? pos : pos-1;

break;
}
}
}
}

@Override
public boolean hasPrevious() {
throw new NotImplementedException();
}

@Override
public TripleID previous() {
throw new NotImplementedException();
}

@Override
public void goTo(long pos) {
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.rdfhdt.hdt.options.HDTOptions;
import org.rdfhdt.hdt.quads.impl.BitmapQuadsIterator;
import org.rdfhdt.hdt.quads.impl.BitmapQuadsIteratorG;
import org.rdfhdt.hdt.quads.impl.BitmapQuadsIteratorZFOQ;
import org.rdfhdt.hdt.quads.impl.BitmapQuadsIteratorZGFOQ;
import org.rdfhdt.hdt.triples.IteratorTripleID;
import org.rdfhdt.hdt.triples.TempTriples;
Expand Down Expand Up @@ -297,6 +298,9 @@ public SuppliableIteratorTripleID search(TripleID pattern) {
}
}

if(patternString.equals("?PO?") || patternString.equals("??O?"))
return new BitmapQuadsIteratorZFOQ(this, pattern);

if(patternString.equals("?POG") || patternString.equals("??OG"))
return new BitmapQuadsIteratorZGFOQ(this, pattern);

Expand Down