use of org.apache.stanbol.entityhub.servicesapi.model.Representation in project stanbol by apache.
the class RdfRepresentationTest method testBNodeFiltering.
/**
* Test for STANBOL-1301
*/
@Test
public void testBNodeFiltering() {
URI concept = new URIImpl("http://example.org/mySkos#Concept123");
Representation r = createRepresentation(concept.stringValue());
assertTrue(r instanceof RdfRepresentation);
RdfRepresentation rep = (RdfRepresentation) r;
//add the example as listed in STANBOL-1301 to directly to the
//Sesame Model backing the created Representation
Model m = rep.getModel();
m.add(concept, RDF.TYPE, SKOS.CONCEPT);
m.add(concept, DCTERMS.IDENTIFIER, new LiteralImpl("123"));
m.add(concept, SKOS.PREF_LABEL, new LiteralImpl("Concept123", "en"));
BNode note1 = new BNodeImpl("5d8580be71044a88bcfe9852d1e9cfb6node17c4j452vx19576");
m.add(concept, SKOS.SCOPE_NOTE, note1);
m.add(note1, DCTERMS.CREATOR, new LiteralImpl("User1"));
m.add(note1, DCTERMS.CREATED, new LiteralImpl("2013-03-03T02:02:02Z", XMLSchema.DATETIME));
m.add(note1, RDFS.COMMENT, new LiteralImpl("The scope of this example global", "en"));
BNode note2 = new BNodeImpl("5d8580be71044a88bcfe9852d1e9cfb6node17c4j452vx19634");
m.add(concept, SKOS.SCOPE_NOTE, note2);
m.add(note2, DCTERMS.CREATOR, new LiteralImpl("User2"));
m.add(note2, DCTERMS.CREATED, new LiteralImpl("2013-03-03T04:04:04Z", XMLSchema.DATETIME));
m.add(note2, RDFS.COMMENT, new LiteralImpl("Der Geltungsbereich ist Global", "de"));
//now assert that BNodes are not reported via the Representation API
Iterator<Object> scopeNotes = rep.get(SKOS.SCOPE_NOTE.stringValue());
assertFalse(scopeNotes.hasNext());
Iterator<Reference> scopeNoteRefs = rep.getReferences(SKOS.SCOPE_NOTE.stringValue());
assertFalse(scopeNoteRefs.hasNext());
}
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");
}
Aggregations