use of org.apache.clerezza.commons.rdf.Triple in project stanbol by apache.
the class TikaEngineTest method verifyBlankNodeOrIRI.
private static BlankNodeOrIRI verifyBlankNodeOrIRI(ContentItem ci, IRI subject, IRI property) {
Iterator<Triple> it = ci.getMetadata().filter(subject, property, null);
assertTrue(it.hasNext());
RDFTerm r = it.next().getObject();
assertFalse(it.hasNext());
assertTrue(r instanceof BlankNodeOrIRI);
return (BlankNodeOrIRI) r;
}
use of org.apache.clerezza.commons.rdf.Triple in project stanbol by apache.
the class TikaEngineTest method verifyValues.
private static Set<Literal> verifyValues(ContentItem ci, BlankNodeOrIRI subject, IRI property, IRI dataType, String... lexValues) {
Iterator<Triple> it = ci.getMetadata().filter(subject, property, null);
assertTrue(it.hasNext());
Set<String> expected = new HashSet<String>(Arrays.asList(lexValues));
Set<Literal> found = new HashSet<Literal>(expected.size());
while (it.hasNext()) {
RDFTerm r = it.next().getObject();
if (dataType == null) {
assertTrue(r instanceof Literal);
} else {
assertTrue(r instanceof Literal);
assertEquals(dataType, ((Literal) r).getDataType());
}
assertTrue(expected.remove(((Literal) r).getLexicalForm()));
found.add((Literal) r);
}
return found;
}
use of org.apache.clerezza.commons.rdf.Triple in project stanbol by apache.
the class TikaEngineTest method testGEOMetadata.
@Test
public void testGEOMetadata() throws EngineException, IOException, ParseException {
log.info(">>> testGEOMetadata <<<");
//first validate Media RDFTerm Ontology
IRI hasLocation = new IRI(NamespaceEnum.media + "hasLocation");
IRI locationLatitude = new IRI(NamespaceEnum.media + "locationLatitude");
IRI locationLongitude = new IRI(NamespaceEnum.media + "locationLongitude");
//IRI locationAltitude = new IRI(NamespaceEnum.media+"locationAltitude");
//"video/x-ms-asf");
ContentItem ci = createContentItem("testJPEG_GEO.jpg", OCTET_STREAM.toString());
assertFalse(engine.canEnhance(ci) == CANNOT_ENHANCE);
engine.computeEnhancements(ci);
Iterator<Triple> it = ci.getMetadata().filter(ci.getUri(), hasLocation, null);
assertTrue(it.hasNext());
RDFTerm r = it.next().getObject();
assertFalse(it.hasNext());
assertTrue(r instanceof BlankNodeOrIRI);
BlankNodeOrIRI location = verifyBlankNodeOrIRI(ci, hasLocation);
//lat
verifyValue(ci, location, locationLatitude, XSD.double_, "12.54321");
//long
verifyValue(ci, location, locationLongitude, XSD.double_, "-54.1234");
//second the GEO ont
IRI lat = new IRI(NamespaceEnum.geo + "lat");
IRI lon = new IRI(NamespaceEnum.geo + "long");
//lat
verifyValue(ci, lat, XSD.double_, "12.54321");
//long
verifyValue(ci, lon, XSD.double_, "-54.1234");
}
use of org.apache.clerezza.commons.rdf.Triple in project stanbol by apache.
the class TikaEngineTest method verifyValue.
private static Literal verifyValue(ContentItem ci, BlankNodeOrIRI subject, IRI property, IRI dataType, String lexValue) throws ParseException {
Iterator<Triple> it = ci.getMetadata().filter(subject, property, null);
assertTrue(it.hasNext());
RDFTerm r = it.next().getObject();
assertFalse(it.hasNext());
if (dataType != null) {
assertEquals(dataType, ((Literal) r).getDataType());
}
//consider the time zone of the host running this test
if (XSD.dateTime.equals(dataType) && lexValue.charAt(lexValue.length() - 1) != 'Z') {
Date expectedDate = dateDefaultTimezone.parse(lexValue);
assertEquals(expectedDate, lf.createObject(Date.class, ((Literal) r)));
} else {
assertEquals(lexValue, ((Literal) r).getLexicalForm());
}
return (Literal) r;
}
use of org.apache.clerezza.commons.rdf.Triple in project stanbol by apache.
the class ClerezzaModelWriter method toRDF.
private Graph toRDF(QueryResultList<?> resultList) {
final Graph resultGraph;
Class<?> type = resultList.getType();
if (String.class.isAssignableFrom(type)) {
//create a new ImmutableGraph
resultGraph = new IndexedGraph();
for (Object result : resultList) {
//add a triple to each reference in the result set
resultGraph.add(new TripleImpl(QUERY_RESULT_LIST, QUERY_RESULT, new IRI(result.toString())));
}
} else {
//first determine the type of the resultList
final boolean isSignType;
if (Representation.class.isAssignableFrom(type)) {
isSignType = false;
} else if (Representation.class.isAssignableFrom(type)) {
isSignType = true;
} else {
//incompatible type -> throw an Exception
throw new IllegalArgumentException("Parsed type " + type + " is not supported");
}
//special treatment for RdfQueryResultList for increased performance
if (resultList instanceof RdfQueryResultList) {
resultGraph = ((RdfQueryResultList) resultList).getResultGraph();
if (isSignType) {
//if we build a ResultList for Signs, that we need to do more things
//first remove all triples representing results
Iterator<Triple> resultTripleIt = resultGraph.filter(QUERY_RESULT_LIST, QUERY_RESULT, null);
while (resultTripleIt.hasNext()) {
resultTripleIt.next();
resultTripleIt.remove();
}
//to the Sign IDs
for (Object result : resultList) {
IRI signId = new IRI(((Entity) result).getId());
addEntityTriplesToGraph(resultGraph, (Entity) result);
resultGraph.add(new TripleImpl(QUERY_RESULT_LIST, QUERY_RESULT, signId));
}
}
} else {
//any other implementation of the QueryResultList interface
//create a new graph
resultGraph = new IndexedGraph();
if (Representation.class.isAssignableFrom(type)) {
for (Object result : resultList) {
IRI resultId;
if (!isSignType) {
addRDFTo(resultGraph, (Representation) result);
resultId = new IRI(((Representation) result).getId());
} else {
addRDFTo(resultGraph, (Entity) result);
resultId = new IRI(((Entity) result).getId());
}
//Note: In case of Representation this Triple points to
// the representation. In case of Signs it points to
// the sign.
resultGraph.add(new TripleImpl(QUERY_RESULT_LIST, QUERY_RESULT, resultId));
}
}
}
}
return resultGraph;
}
Aggregations