use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class YardSite method getEntity.
@Override
public Entity getEntity(String id) throws ManagedSiteException {
Representation rep;
try {
rep = getYard().getRepresentation(id);
} catch (YardException e) {
throw new ManagedSiteException(e.getMessage(), e);
}
if (rep != null) {
Entity entity = new EntityImpl(config.getId(), rep, null);
SiteUtils.initEntityMetadata(entity, siteMetadata, null);
return entity;
} else {
return null;
}
}
use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class YardSite method store.
/**
* Stores the parsed representations to the Yard and also applies the
* configured {@link #getFieldMapper() FieldMappings}.
* @param The representations to store
*/
@Override
public void store(final Iterable<Representation> representations) throws ManagedSiteException {
try {
Yard yard = getYard();
final ValueFactory vf = yard.getValueFactory();
yard.store(new Iterable<Representation>() {
@Override
public Iterator<Representation> iterator() {
return new Iterator<Representation>() {
Iterator<Representation> it = representations.iterator();
@Override
public boolean hasNext() {
return it.hasNext();
}
@Override
public Representation next() {
Representation next = it.next();
fieldMapper.applyMappings(next, next, vf);
return next;
}
@Override
public void remove() {
it.remove();
}
};
}
});
} catch (YardException e) {
throw new ManagedSiteException(e.getMessage(), e);
}
}
use of org.apache.stanbol.entityhub.servicesapi.model.Representation 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;
}
use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class LDPathTestBase method testSetup.
/**
* Tests that the yard is setup correctly by checking for the
* {@link Representation}s of the ids returned by {@link #checkContexts()}.
* <p>
* This methods should make is more easy to detect if a failure of a test
* is because of a wrong setup of the Yard.
* @throws Exception
*/
@Test
public void testSetup() throws Exception {
log.info("check Setup");
for (String context : checkContexts()) {
Representation rep = yard.getRepresentation(context);
log.info(" > check Entity {}", rep.getId());
assertNotNull(rep);
assertEquals(rep.getId(), context);
if (log.isInfoEnabled()) {
log.info("Data for Entity {}: \n {}", rep.getId(), ModelUtils.getRepresentationInfo(rep));
}
}
log.info(" ... check completed");
}
use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class RdfRepresentationTest method testTypedLiteralToTextConversion.
/**
* {@link TypedLiteral}s are used to represent literal values for different
* xsd dataTypes within Clerezza. This method tests of {@link TypedLiteral}s
* with the data type xsd:string are correctly treated like {@link String}
* values. This tests especially if they are treated as natural language
* texts without language.
*/
@Test
public void testTypedLiteralToTextConversion() {
String field = "urn:test.RdfRepresentation:test.field";
Literal stringLiteral = literalFactory.createTypedLiteral("This is a stirng value");
//also add an integer to test that other typed literals are not used as texts
Literal integerLiteral = literalFactory.createTypedLiteral(new Integer(5));
Representation rep = createRepresentation(null);
rep.add(field, Arrays.asList(stringLiteral, integerLiteral));
//test if the literal is returned when asking for natural language text without language
Iterator<Text> noLangTexts = rep.get(field, (String) null);
assertTrue(noLangTexts.hasNext());
assertEquals(stringLiteral.getLexicalForm(), noLangTexts.next().getText());
assertFalse(noLangTexts.hasNext());
//test that string literals are returned when asking for all natural language text values
Iterator<Text> texts = rep.getText(field);
assertTrue(texts.hasNext());
assertEquals(stringLiteral.getLexicalForm(), texts.next().getText());
assertFalse(texts.hasNext());
}
Aggregations