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")));
}
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());
}
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")));
}
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());
}
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();
}
Aggregations