Search in sources :

Example 71 with IRI

use of org.apache.clerezza.commons.rdf.IRI 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 72 with IRI

use of org.apache.clerezza.commons.rdf.IRI 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 73 with IRI

use of org.apache.clerezza.commons.rdf.IRI 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)

Example 74 with IRI

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

the class ContentItemBackendTest method testSuggestedEntityWithoutParsedContext.

@Test
public void testSuggestedEntityWithoutParsedContext() throws LDPathParseException {
    // The suggestedEntity function can be used for twi usecases
    // (1) get the {limit} top rated linked Entities per parsed context
    // In this example we parse all TextAnnotations
    // NOTE: '.' MUST BE used as first argument in this case
    String path = "fn:textAnnotation()/fn:suggestedEntity(\"1\")";
    Collection<RDFTerm> result = ldpath.pathQuery(ci.getUri(), path, null);
    assertNotNull(result);
    assertFalse(result.isEmpty());
    assertTrue(result.size() == 2);
    Set<IRI> expectedValues = new HashSet<IRI>(Arrays.asList(new IRI("http://dbpedia.org/resource/Paris"), new IRI("http://dbpedia.org/resource/Bob_Marley")));
    for (RDFTerm r : result) {
        assertTrue(r instanceof IRI);
        log.info("Entity: {}", r);
        assertTrue(expectedValues.remove(r));
    }
    assertTrue(expectedValues.isEmpty());
    // (2) get the {limit} top rated Entities for all Annotations parsed
    // as the first argument
    // NOTE: the selector parsing all Annotations MUST BE used as first
    // argument
    path = "fn:suggestedEntity(fn:textAnnotation(),\"1\")";
    result = ldpath.pathQuery(ci.getUri(), path, null);
    assertNotNull(result);
    assertFalse(result.isEmpty());
    assertTrue(result.size() == 1);
    assertEquals(new IRI("http://dbpedia.org/resource/Paris"), result.iterator().next());
}
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 75 with IRI

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

the class RefactorResource method performRefactoringLazyCreateGraph.

@GET
public Response performRefactoringLazyCreateGraph(@QueryParam("recipe") String recipe, @QueryParam("input-graph") String inputGraph, @QueryParam("output-graph") String outputGraph, @Context HttpHeaders headers) {
    log.info("recipe: {}", recipe);
    log.info("input-graph: {}", inputGraph);
    log.info("output-graph: {}", outputGraph);
    IRI recipeID = new IRI(recipe);
    IRI inputGraphID = new IRI(inputGraph);
    IRI outputGraphID = new IRI(outputGraph);
    // Refactorer semionRefactorer = semionManager.getRegisteredRefactorer();
    ResponseBuilder responseBuilder = null;
    try {
        refactorer.graphRefactoring(outputGraphID, inputGraphID, recipeID);
        responseBuilder = Response.ok();
    } catch (RefactoringException e) {
        // refactoring exceptions are re-thrown
        log.error(e.getMessage(), e);
        throw new WebApplicationException(e, INTERNAL_SERVER_ERROR);
    } catch (NoSuchRecipeException e) {
        log.error(e.getMessage(), e);
        responseBuilder = Response.status(NOT_FOUND);
    }
    MediaType mediaType = MediaTypeUtil.getAcceptableMediaType(headers, null);
    if (mediaType != null)
        responseBuilder.header(HttpHeaders.CONTENT_TYPE, mediaType);
    // addCORSOrigin(servletContext, responseBuilder, headers);
    return responseBuilder.build();
}
Also used : IRI(org.apache.clerezza.commons.rdf.IRI) WebApplicationException(javax.ws.rs.WebApplicationException) NoSuchRecipeException(org.apache.stanbol.rules.base.api.NoSuchRecipeException) MediaType(javax.ws.rs.core.MediaType) RefactoringException(org.apache.stanbol.rules.refactor.api.RefactoringException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) GET(javax.ws.rs.GET)

Aggregations

IRI (org.apache.clerezza.commons.rdf.IRI)346 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)113 Graph (org.apache.clerezza.commons.rdf.Graph)109 TripleImpl (org.apache.clerezza.commons.rdf.impl.utils.TripleImpl)104 Triple (org.apache.clerezza.commons.rdf.Triple)88 RDFTerm (org.apache.clerezza.commons.rdf.RDFTerm)84 Test (org.junit.Test)78 PlainLiteralImpl (org.apache.clerezza.commons.rdf.impl.utils.PlainLiteralImpl)58 HashSet (java.util.HashSet)50 ContentItem (org.apache.stanbol.enhancer.servicesapi.ContentItem)46 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)39 HashMap (java.util.HashMap)38 IOException (java.io.IOException)37 ArrayList (java.util.ArrayList)37 Blob (org.apache.stanbol.enhancer.servicesapi.Blob)36 Literal (org.apache.clerezza.commons.rdf.Literal)35 SimpleGraph (org.apache.clerezza.commons.rdf.impl.utils.simple.SimpleGraph)31 IndexedGraph (org.apache.stanbol.commons.indexedgraph.IndexedGraph)29 Recipe (org.apache.stanbol.rules.base.api.Recipe)29 Language (org.apache.clerezza.commons.rdf.Language)24