use of fr.lirmm.graphik.util.Prefix in project graal by graphik-team.
the class DlgpParser method parse.
// /////////////////////////////////////////////////////////////////////////
// PRIVATE
// /////////////////////////////////////////////////////////////////////////
private static Object parse(String s) throws ParseException {
InMemoryStream<Object> stream = new QueueStream<Object>();
Producer p = new Producer(new StringReader(s), stream);
try {
p.run();
} catch (Throwable t) {
throw new DlgpParseException(t);
}
if (!stream.hasNext()) {
throw new DlgpParseException("No statement found.");
}
Object o = null;
do {
o = stream.next();
} while (o instanceof Directive || o instanceof Prefix);
if (stream.hasNext()) {
throw new DlgpParseException("Too much statements.");
}
stream.close();
if (o instanceof ParseException) {
throw (ParseException) o;
}
return o;
}
use of fr.lirmm.graphik.util.Prefix in project graal by graphik-team.
the class SparqlRuleTest method test0.
@Test
public void test0() throws IOException {
String queryString = "PREFIX foaf: <http://xmlns.com/foaf/0.1/> " + " PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#> " + " " + " CONSTRUCT { ?x vcard:N _:v . " + " _:v vcard:givenName ?gname . " + " _:v vcard:familyName ?fname } " + " WHERE " + " { " + " { ?x foaf:firstname ?gname } . " + " { ?x foaf:surname ?fname } . " + " }";
SparqlRuleParser parser = new SparqlRuleParser(queryString);
StringWriter sw = new StringWriter();
SparqlRuleWriter writer = new SparqlRuleWriter(sw);
for (Prefix p : parser.getPrefixes()) writer.write(p);
writer.write(parser.getRule());
writer.close();
String s = sw.toString();
try {
parser = new SparqlRuleParser(s);
} catch (QueryParseException e) {
Assert.assertFalse("QueryParseException", true);
}
}
use of fr.lirmm.graphik.util.Prefix in project graal by graphik-team.
the class SparqlConjunctiveQueryParser method execute.
// /////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
// /////////////////////////////////////////////////////////////////////////
private void execute(String queryString) {
this.prefixes = new LinkedList<Prefix>();
List<Term> ans = new LinkedList<Term>();
Query sparql = QueryFactory.create(queryString);
for (Map.Entry<String, String> e : sparql.getPrefixMapping().getNsPrefixMap().entrySet()) {
this.prefixes.add(new Prefix(e.getKey(), e.getValue()));
}
if (sparql.isSelectType()) {
for (String v : sparql.getResultVars()) {
ans.add(DefaultTermFactory.instance().createVariable(v));
}
}
ElementVisitorImpl visitor = new ElementVisitorImpl(DefaultAtomSetFactory.instance().create());
sparql.getQueryPattern().visit(visitor);
// check if answer variables appear in the query body
Set<Variable> bodyVars = visitor.getAtomSet().getVariables();
for (Term t : ans) {
if (t.isVariable() && !bodyVars.contains(t)) {
throw new ParseError("The variable [" + t + "] of the answer list does not appear in the query body.");
}
}
this.query = DefaultConjunctiveQueryFactory.instance().create(visitor.getAtomSet(), ans);
}
use of fr.lirmm.graphik.util.Prefix in project graal by graphik-team.
the class SparqlRuleParser method execute.
// /////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
// /////////////////////////////////////////////////////////////////////////
private void execute(String sparqlQuery) {
Query sparql = QueryFactory.create(sparqlQuery);
this.prefixes = new LinkedList<Prefix>();
for (Map.Entry<String, String> e : sparql.getPrefixMapping().getNsPrefixMap().entrySet()) {
this.prefixes.add(new Prefix(e.getKey(), e.getValue()));
}
Rule rule = new DefaultRule();
if (sparql.isConstructType()) {
Template template = sparql.getConstructTemplate();
for (Triple triple : template.getTriples()) {
rule.getHead().add(SparqlUtils.triple2Atom(triple));
}
}
ElementVisitorImpl visitor = new ElementVisitorImpl(rule.getBody());
sparql.getQueryPattern().visit(visitor);
this.rule = rule;
}
use of fr.lirmm.graphik.util.Prefix in project graal by graphik-team.
the class OWL2ParserTest method partiallyIllegalTest.
@Test
public void partiallyIllegalTest() throws OWL2ParserException {
OWL2Parser parser = new OWL2Parser(PREFIXES + " :A a owl:Class. " + ":B a owl:Class. " + ":C a owl:Class. " + ":p a owl:ObjectProperty. " + "[rdf:type owl:Restriction; " + " owl:onProperty :p; " + " owl:someValuesFrom [owl:unionOf ( [rdf:type owl:Restriction; " + " owl:onProperty :p ; " + " owl:allValuesFrom :A] :C ) ]" + "] rdfs:subClassOf :B .");
int nbAssertion = 0;
while (parser.hasNext()) {
Object o = parser.next();
if (!(o instanceof Prefix)) {
++nbAssertion;
}
}
parser.close();
Assert.assertEquals("Number of assertions found:", 1, nbAssertion);
}
Aggregations