use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.
the class RDF4jStore method termsByPredicatePosition.
@Override
public CloseableIterator<Term> termsByPredicatePosition(Predicate p, int position) throws AtomSetException {
TupleQuery query = null;
TupleQueryResult results = null;
try {
if (position == 0) {
query = this.connection.prepareTupleQuery(QueryLanguage.SPARQL, "SELECT DISTINCT ?x WHERE { ?x <" + utils.createURI(p) + "> ?y }");
} else if (position == 1) {
query = this.connection.prepareTupleQuery(QueryLanguage.SPARQL, "SELECT DISTINCT ?x WHERE { ?y <" + utils.createURI(p) + "> ?x }");
} else {
throw new WrongArityException("Position should be 0 for subject or 1 for object.");
}
results = query.evaluate();
} catch (RepositoryException e) {
throw new AtomSetException(e);
} catch (MalformedQueryException e) {
throw new AtomSetException(e);
} catch (QueryEvaluationException e) {
throw new AtomSetException(e);
}
return new TermsIterator(results, "x", this.utils);
}
use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.
the class AbstractAtomSet method getTerms.
@Override
public Set<Term> getTerms() throws AtomSetException {
Set<Term> terms = new HashSet<Term>();
CloseableIterator<Atom> atomIt = this.iterator();
try {
while (atomIt.hasNext()) {
Iterator<Term> termIt = atomIt.next().iterator();
while (termIt.hasNext()) {
terms.add(termIt.next());
}
}
} catch (Exception e) {
throw new AtomSetException(e);
}
return terms;
}
use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.
the class AbstractAtomSet method getLiterals.
@Override
public Set<Literal> getLiterals() throws AtomSetException {
Set<Literal> terms = new HashSet<Literal>();
CloseableIterator<Atom> atomIt = this.iterator();
try {
while (atomIt.hasNext()) {
Iterator<Term> termIt = atomIt.next().iterator();
while (termIt.hasNext()) {
Term t = termIt.next();
if (t.isLiteral()) {
terms.add((Literal) t);
}
}
}
} catch (Exception e) {
throw new AtomSetException(e);
}
return terms;
}
use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.
the class AbstractAtomSet method getVariables.
@Override
public Set<Variable> getVariables() throws AtomSetException {
Set<Variable> terms = new HashSet<Variable>();
CloseableIterator<Atom> atomIt = this.iterator();
try {
while (atomIt.hasNext()) {
Iterator<Term> termIt = atomIt.next().iterator();
while (termIt.hasNext()) {
Term t = termIt.next();
if (t.isVariable()) {
terms.add((Variable) t);
}
}
}
} catch (Exception e) {
throw new AtomSetException(e);
}
return terms;
}
use of fr.lirmm.graphik.graal.api.core.AtomSetException in project graal by graphik-team.
the class StarBootstrapper method exec.
// /////////////////////////////////////////////////////////////////////////
//
// /////////////////////////////////////////////////////////////////////////
@Override
public CloseableIterator<Term> exec(final VarSharedData v, Collection<Atom> preAtoms, Collection<Atom> postAtoms, final AtomSet data, RulesCompilation compilation) throws BacktrackException {
Set<Term> terms = null;
if (this.getProfiler() != null) {
this.getProfiler().start("BootstrapTime");
this.getProfiler().start("BootstrapTimeFirstPart");
}
Iterator<Atom> it;
Collection<Constant> constants = null;
Atom aa = null;
it = postAtoms.iterator();
while (it.hasNext()) {
Atom a = it.next();
if (constants == null || constants.isEmpty()) {
constants = a.getConstants();
aa = a;
}
}
it = preAtoms.iterator();
while (it.hasNext()) {
Atom a = it.next();
if (constants == null || constants.isEmpty()) {
constants = a.getConstants();
aa = a;
}
}
try {
if (constants != null && !constants.isEmpty()) {
terms = new TreeSet<Term>(TermValueComparator.instance());
for (Pair<Atom, Substitution> im : compilation.getRewritingOf(aa)) {
int pos = im.getLeft().indexOf(im.getRight().createImageOf(v.value));
CloseableIterator<Atom> match = data.match(im.getLeft());
while (match.hasNext()) {
terms.add(match.next().getTerm(pos));
}
}
}
if (this.getProfiler() != null) {
this.getProfiler().stop("BootstrapTimeFirstPart");
}
if (terms == null) {
it = postAtoms.iterator();
while (it.hasNext()) {
if (terms == null) {
terms = BootstrapperUtils.computeCandidatesOverRewritings(it.next(), v, data, compilation);
} else {
terms.retainAll(BootstrapperUtils.computeCandidatesOverRewritings(it.next(), v, data, compilation));
}
}
it = preAtoms.iterator();
while (it.hasNext()) {
if (terms == null) {
terms = BootstrapperUtils.computeCandidatesOverRewritings(it.next(), v, data, compilation);
} else {
terms.retainAll(BootstrapperUtils.computeCandidatesOverRewritings(it.next(), v, data, compilation));
}
}
}
if (this.getProfiler() != null) {
this.getProfiler().stop("BootstrapTime");
}
if (terms == null) {
return data.termsIterator();
} else {
return new CloseableIteratorAdapter<Term>(terms.iterator());
}
} catch (AtomSetException e) {
throw new BacktrackException(e);
} catch (IteratorException e) {
throw new BacktrackException(e);
}
}
Aggregations