Search in sources :

Example 6 with RDFTerm

use of org.apache.clerezza.commons.rdf.RDFTerm in project stanbol by apache.

the class ContentItemBackendTest method testEnhancements.

@Test
public void testEnhancements() throws LDPathParseException {
    String path = "fn:enhancement(.)";
    Collection<RDFTerm> result = ldpath.pathQuery(ci.getUri(), path, null);
    assertNotNull(result);
    assertFalse(result.isEmpty());
    assertTrue(result.size() == 7);
    for (RDFTerm r : result) {
        assertTrue(r instanceof IRI);
        log.info("Entity: {}", r);
    }
    //and with a filter
    path = "fn:enhancement(.)[rdf:type is fise:TextAnnotation]";
    result = ldpath.pathQuery(ci.getUri(), path, null);
    assertNotNull(result);
    assertFalse(result.isEmpty());
    assertTrue(result.size() == 3);
    //        assertTrue(result.contains(new IRI("http://dbpedia.org/resource/Bob_Marley")));
    path = "fn:enhancement(.)/dc:language";
    result = ldpath.pathQuery(ci.getUri(), path, null);
    assertNotNull(result);
    assertFalse(result.isEmpty());
    assertTrue(result.size() == 1);
    RDFTerm r = result.iterator().next();
    assertTrue(r instanceof Literal);
    assertEquals("en", ((Literal) r).getLexicalForm());
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) Literal(org.apache.clerezza.commons.rdf.Literal) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm) Test(org.junit.Test)

Example 7 with RDFTerm

use of org.apache.clerezza.commons.rdf.RDFTerm in project stanbol by apache.

the class ContentItemBackendTest method testContent.

@Test
public void testContent() throws LDPathParseException {
    Collection<RDFTerm> result = ldpath.pathQuery(ci.getUri(), "fn:content(\"text/plain\")", null);
    assertNotNull(result);
    assertFalse(result.isEmpty());
    assertTrue(result.size() == 1);
    RDFTerm r = result.iterator().next();
    assertTrue(r instanceof Literal);
    String content = ((Literal) r).getLexicalForm();
    assertEquals(content, textContent);
    result = ldpath.pathQuery(ci.getUri(), "fn:content(\"text/html\")", null);
    assertNotNull(result);
    assertFalse(result.isEmpty());
    assertTrue(result.size() == 1);
    r = result.iterator().next();
    assertTrue(r instanceof Literal);
    content = ((Literal) r).getLexicalForm();
    assertEquals(content, htmlContent);
}
Also used : Literal(org.apache.clerezza.commons.rdf.Literal) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm) Test(org.junit.Test)

Example 8 with RDFTerm

use of org.apache.clerezza.commons.rdf.RDFTerm in project stanbol by apache.

the class ContentItemBackendTest method testTextAnnotationFunctionWithoutParsedContext.

@Test
public void testTextAnnotationFunctionWithoutParsedContext() throws LDPathParseException {
    String path = "fn:textAnnotation()/fise:selected-text";
    Collection<RDFTerm> result = ldpath.pathQuery(ci.getUri(), path, null);
    assertNotNull(result);
    assertFalse(result.isEmpty());
    assertTrue(result.size() == 2);
    Set<String> expectedValues = new HashSet<String>(Arrays.asList("Bob Marley", "Paris"));
    for (RDFTerm r : result) {
        assertTrue(r instanceof Literal);
        assertTrue(expectedValues.remove(((Literal) r).getLexicalForm()));
    }
    assertTrue(expectedValues.isEmpty());
    //test with a filter for the type
    //same as the 1st example bat rather using an ld-path construct for
    //filtering for TextAnnotations representing persons
    path = "fn:textAnnotation()[dc:type is dbpedia-ont:Person]/fise:selected-text";
    result = ldpath.pathQuery(ci.getUri(), path, null);
    assertNotNull(result);
    assertFalse(result.isEmpty());
    assertTrue(result.size() == 1);
    RDFTerm r = result.iterator().next();
    assertTrue(r instanceof Literal);
    assertEquals(((Literal) r).getLexicalForm(), "Bob Marley");
}
Also used : Literal(org.apache.clerezza.commons.rdf.Literal) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with RDFTerm

use of org.apache.clerezza.commons.rdf.RDFTerm in project stanbol by apache.

the class ContentItemBackendTest method testEntityAnnotation.

@Test
public void testEntityAnnotation() throws LDPathParseException {
    String path = "fn:entityAnnotation(.)/fise:entity-reference";
    Collection<RDFTerm> result = ldpath.pathQuery(ci.getUri(), path, null);
    assertNotNull(result);
    assertFalse(result.isEmpty());
    assertTrue(result.size() == 4);
    Set<IRI> expectedValues = new HashSet<IRI>(Arrays.asList(new IRI("http://dbpedia.org/resource/Paris"), new IRI("http://dbpedia.org/resource/Bob_Marley"), new IRI("http://dbpedia.org/resource/Centre_Georges_Pompidou"), new IRI("http://dbpedia.org/resource/Paris,_Texas")));
    for (RDFTerm r : result) {
        assertTrue(r instanceof IRI);
        log.info("Entity: {}", r);
        assertTrue(expectedValues.remove(r));
    }
    assertTrue(expectedValues.isEmpty());
    //and with a filter
    path = "fn:entityAnnotation(.)[fise:entity-type is dbpedia-ont:Person]/fise:entity-reference";
    result = ldpath.pathQuery(ci.getUri(), path, null);
    assertNotNull(result);
    assertFalse(result.isEmpty());
    assertTrue(result.size() == 1);
    assertTrue(result.contains(new IRI("http://dbpedia.org/resource/Bob_Marley")));
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with RDFTerm

use of org.apache.clerezza.commons.rdf.RDFTerm in project stanbol by apache.

the class ContentItemBackendTest method testEntityAnnotationWithoutParsedContext.

@Test
public void testEntityAnnotationWithoutParsedContext() throws LDPathParseException {
    String path = "fn:entityAnnotation()/fise:entity-reference";
    Collection<RDFTerm> result = ldpath.pathQuery(ci.getUri(), path, null);
    assertNotNull(result);
    assertFalse(result.isEmpty());
    assertTrue(result.size() == 4);
    Set<IRI> expectedValues = new HashSet<IRI>(Arrays.asList(new IRI("http://dbpedia.org/resource/Paris"), new IRI("http://dbpedia.org/resource/Bob_Marley"), new IRI("http://dbpedia.org/resource/Centre_Georges_Pompidou"), new IRI("http://dbpedia.org/resource/Paris,_Texas")));
    for (RDFTerm r : result) {
        assertTrue(r instanceof IRI);
        log.info("Entity: {}", r);
        assertTrue(expectedValues.remove(r));
    }
    assertTrue(expectedValues.isEmpty());
    //and with a filter
    path = "fn:entityAnnotation()[fise:entity-type is dbpedia-ont:Person]/fise:entity-reference";
    result = ldpath.pathQuery(ci.getUri(), path, null);
    assertNotNull(result);
    assertFalse(result.isEmpty());
    assertTrue(result.size() == 1);
    assertTrue(result.contains(new IRI("http://dbpedia.org/resource/Bob_Marley")));
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) RDFTerm(org.apache.clerezza.commons.rdf.RDFTerm) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)126 IRI (org.apache.clerezza.commons.rdf.IRI)84 Triple (org.apache.clerezza.commons.rdf.Triple)70 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)48 Literal (org.apache.clerezza.commons.rdf.Literal)35 Test (org.junit.Test)35 HashSet (java.util.HashSet)30 HashMap (java.util.HashMap)28 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)26 Graph (org.apache.clerezza.commons.rdf.Graph)24 ContentItem (org.apache.stanbol.enhancer.servicesapi.ContentItem)18 ArrayList (java.util.ArrayList)17 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)16 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)13 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)13 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)12 Collection (java.util.Collection)10 IndexedGraph (org.apache.stanbol.commons.indexedgraph.IndexedGraph)10 Lock (java.util.concurrent.locks.Lock)9 IOException (java.io.IOException)5