Search in sources :

Example 11 with Prefix

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);
    }
}
Also used : OWL2Parser(fr.lirmm.graphik.graal.io.owl.OWL2Parser) Prefix(fr.lirmm.graphik.util.Prefix) Rule(fr.lirmm.graphik.graal.api.core.Rule) Atom(fr.lirmm.graphik.graal.api.core.Atom) OWL2ParserException(fr.lirmm.graphik.graal.io.owl.OWL2ParserException) CloseableIteratorWithoutException(fr.lirmm.graphik.util.stream.CloseableIteratorWithoutException) IteratorException(fr.lirmm.graphik.util.stream.IteratorException) Test(org.junit.Test)

Example 12 with Prefix

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());
    }
}
Also used : Prefix(fr.lirmm.graphik.util.Prefix)

Example 13 with Prefix

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('>');
        }
    }
}
Also used : Prefix(fr.lirmm.graphik.util.Prefix)

Example 14 with Prefix

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>)."));
}
Also used : DefaultAtom(fr.lirmm.graphik.graal.core.DefaultAtom) Prefix(fr.lirmm.graphik.util.Prefix) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DefaultURI(fr.lirmm.graphik.util.DefaultURI) Predicate(fr.lirmm.graphik.graal.api.core.Predicate) Test(org.junit.Test)

Example 15 with Prefix

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;
}
Also used : DefaultPrefixManager(org.semanticweb.owlapi.util.DefaultPrefixManager) TreeSet(java.util.TreeSet) OWLDocumentFormat(org.semanticweb.owlapi.model.OWLDocumentFormat) PrefixDocumentFormat(org.semanticweb.owlapi.formats.PrefixDocumentFormat) Prefix(fr.lirmm.graphik.util.Prefix) Map(java.util.Map)

Aggregations

Prefix (fr.lirmm.graphik.util.Prefix)33 Test (org.junit.Test)27 OWL2Parser (fr.lirmm.graphik.graal.io.owl.OWL2Parser)23 DefaultNegativeConstraint (fr.lirmm.graphik.graal.core.DefaultNegativeConstraint)17 Rule (fr.lirmm.graphik.graal.api.core.Rule)14 Atom (fr.lirmm.graphik.graal.api.core.Atom)6 Term (fr.lirmm.graphik.graal.api.core.Term)3 Map (java.util.Map)3 Query (com.hp.hpl.jena.query.Query)2 InMemoryAtomSet (fr.lirmm.graphik.graal.api.core.InMemoryAtomSet)2 Predicate (fr.lirmm.graphik.graal.api.core.Predicate)2 DefaultAtom (fr.lirmm.graphik.graal.core.DefaultAtom)2 OWL2ParserException (fr.lirmm.graphik.graal.io.owl.OWL2ParserException)2 DefaultURI (fr.lirmm.graphik.util.DefaultURI)2 CloseableIteratorWithoutException (fr.lirmm.graphik.util.stream.CloseableIteratorWithoutException)2 IteratorException (fr.lirmm.graphik.util.stream.IteratorException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Triple (com.hp.hpl.jena.graph.Triple)1 QueryParseException (com.hp.hpl.jena.query.QueryParseException)1 Template (com.hp.hpl.jena.sparql.syntax.Template)1