use of fr.lirmm.graphik.util.Prefix in project graal by graphik-team.
the class OWL2ParserTest method objectPropertyDomain.
@Test
public void objectPropertyDomain() {
// C(Y) :- p(X, Y).
try {
OWL2Parser parser = new OWL2Parser(PREFIXES + ":p rdf:type owl:ObjectProperty . " + ":A rdf:type owl:Class . " + ":p rdfs:domain :A .");
boolean found = false;
while (parser.hasNext()) {
Object o = parser.next();
if (!(o instanceof Prefix)) {
Rule r = (Rule) o;
Atom property = (Atom) r.getBody().iterator().next();
Assert.assertEquals(P, property.getPredicate());
Atom classs = (Atom) r.getHead().iterator().next();
Assert.assertEquals(A, classs.getPredicate());
Assert.assertEquals(property.getTerm(0), classs.getTerm(0));
found = true;
}
}
parser.close();
Assert.assertTrue("Number of assertions found:", found);
} catch (Exception e) {
Assert.assertFalse(e.getMessage(), true);
}
}
use of fr.lirmm.graphik.util.Prefix in project graal by graphik-team.
the class AbstractSparqlWriter method writeURI.
// /////////////////////////////////////////////////////////////////////////
// PROTECTED METHODS
// /////////////////////////////////////////////////////////////////////////
protected void writeURI(URI uri) throws IOException {
Prefix prefix = this.pm.getPrefixByValue(uri.getPrefix());
if (prefix == null) {
this.write('<');
this.write(uri.toString());
this.write('>');
} else {
this.write(prefix.getPrefixName() + ":" + uri.getLocalname());
}
}
use of fr.lirmm.graphik.util.Prefix in project graal by graphik-team.
the class DlgpWriter method writeURI.
protected void writeURI(URI uri) throws IOException {
if (base != null && uri.toString().startsWith(base)) {
this.writeLowerIdentifier(uri.toString().substring(base.length()));
} else {
Prefix prefix = this.pm.getPrefixByValue(uri.getPrefix());
boolean isPrefixable = prefix != null && DlgpGrammarUtils.checkLocalName(uri.getLocalname());
if (isPrefixable) {
this.write(prefix.getPrefixName() + ":" + uri.getLocalname());
} else {
this.write('<');
this.write(encode(uri.toString()));
this.write('>');
}
}
}
use of fr.lirmm.graphik.util.Prefix in project graal by graphik-team.
the class DlgpWriterTest method bugIllegalCharInPrefixedName.
@Test
public void bugIllegalCharInPrefixedName() throws IOException {
Prefix p1 = new Prefix("a", "http://p#");
Predicate p = new Predicate(new DefaultURI("http://p#to@to"), 1);
ByteArrayOutputStream os = new ByteArrayOutputStream();
DlgpWriter writer = new DlgpWriter(os);
writer.write(p1);
writer.write(new DefaultAtom(p, cst));
writer.flush();
String s = new String(os.toByteArray(), "UTF-8");
writer.close();
Assert.assertTrue(s.contains("<http://p#to@to>(<A>)."));
}
use of fr.lirmm.graphik.util.Prefix in project graal by graphik-team.
the class OWL2Parser method getShortFormProvider.
// /////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
// /////////////////////////////////////////////////////////////////////////
private ShortFormProvider getShortFormProvider(OWLOntology ontology) {
OWLDocumentFormat format = this.manager.getOntologyFormat(this.ontology);
DefaultPrefixManager pm = new DefaultPrefixManager();
if (prefixEnable && format.isPrefixOWLOntologyFormat()) {
PrefixDocumentFormat prefixFormat = format.asPrefixOWLOntologyFormat();
Map<String, String> prefixMap = prefixFormat.getPrefixName2PrefixMap();
Set<String> forbiddenPrefix = new TreeSet<>();
forbiddenPrefix.add("xml:");
forbiddenPrefix.add("rdf:");
forbiddenPrefix.add("rdfs:");
forbiddenPrefix.add("owl:");
for (Map.Entry<String, String> entry : prefixMap.entrySet()) {
String prefix = entry.getKey();
if (!forbiddenPrefix.contains(prefix)) {
pm.setPrefix(prefix, entry.getValue());
prefix = prefix.substring(0, prefix.length() - 1);
buffer.write(new Prefix(prefix, entry.getValue()));
}
}
}
return pm;
}
Aggregations