use of org.openrdf.model.URI in project qi4j-sdk by Qi4j.
the class EntityStateSerializer method serializeProperty.
private void serializeProperty(PropertyDescriptor persistentProperty, Object property, Resource subject, Graph graph, boolean includeNonQueryable) {
if (!(includeNonQueryable || persistentProperty.queryable())) {
// Skip non-queryable
return;
}
ValueType valueType = persistentProperty.valueType();
final ValueFactory valueFactory = graph.getValueFactory();
String propertyURI = persistentProperty.qualifiedName().toURI();
URI predicate = valueFactory.createURI(propertyURI);
String baseURI = propertyURI.substring(0, propertyURI.indexOf('#')) + "/";
if (valueType instanceof ValueCompositeType) {
serializeValueComposite(subject, predicate, (ValueComposite) property, valueType, graph, baseURI, includeNonQueryable);
} else {
String stringProperty = valueSerializer.serialize(new Options().withoutTypeInfo(), property);
final Literal object = valueFactory.createLiteral(stringProperty);
graph.add(subject, predicate, object);
}
}
use of org.openrdf.model.URI in project qi4j-sdk by Qi4j.
the class EntityTypeSerializer method serialize.
public Iterable<Statement> serialize(final EntityDescriptor entityDescriptor) {
Graph graph = new GraphImpl();
ValueFactory values = graph.getValueFactory();
URI entityTypeUri = values.createURI(Classes.toURI(first(entityDescriptor.types())));
graph.add(entityTypeUri, Rdfs.TYPE, Rdfs.CLASS);
graph.add(entityTypeUri, Rdfs.TYPE, OWL.CLASS);
graph.add(entityTypeUri, Qi4jEntityType.TYPE, values.createLiteral(first(entityDescriptor.types()).toString()));
graph.add(entityTypeUri, Qi4jEntityType.QUERYABLE, values.createLiteral(entityDescriptor.queryable()));
serializeMixinTypes(entityDescriptor, graph, entityTypeUri);
serializePropertyTypes(entityDescriptor, graph, entityTypeUri);
serializeAssociationTypes(entityDescriptor, graph, entityTypeUri);
serializeManyAssociationTypes(entityDescriptor, graph, entityTypeUri);
return graph;
}
use of org.openrdf.model.URI in project qi4j-sdk by Qi4j.
the class EntityTypeSerializer method serializeAssociationTypes.
private void serializeAssociationTypes(final EntityDescriptor entityDescriptor, final Graph graph, final URI entityTypeUri) {
ValueFactory values = graph.getValueFactory();
// Associations
for (AssociationDescriptor associationType : entityDescriptor.state().associations()) {
URI associationURI = values.createURI(associationType.qualifiedName().toURI());
graph.add(associationURI, Rdfs.DOMAIN, entityTypeUri);
graph.add(associationURI, Rdfs.TYPE, Rdfs.PROPERTY);
URI associatedURI = values.createURI(Classes.toURI(Classes.RAW_CLASS.map(associationType.type())));
graph.add(associationURI, Rdfs.RANGE, associatedURI);
graph.add(associationURI, Rdfs.RANGE, XMLSchema.ANYURI);
}
}
use of org.openrdf.model.URI in project stanbol by apache.
the class RdfRepresentation method addNaturalText.
@Override
public void addNaturalText(String field, String text, String... languages) throws IllegalArgumentException {
if (field == null) {
throw new IllegalArgumentException("The parsed field MUST NOT be NULL");
} else if (field.isEmpty()) {
throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
}
if (text == null) {
throw new IllegalArgumentException("NULL values are not supported by Representations");
}
URI property = sesameFactory.createURI(field);
if (languages == null || languages.length == 0) {
languages = new String[] { null };
}
for (String language : languages) {
Literal value = sesameFactory.createLiteral(text, language);
addValue(property, value);
}
}
use of org.openrdf.model.URI in project stanbol by apache.
the class RdfRepresentation method add.
@Override
public void add(String field, Object value) throws IllegalArgumentException {
if (field == null) {
throw new IllegalArgumentException("The parsed field MUST NOT be NULL");
} else if (field.isEmpty()) {
throw new IllegalArgumentException("The parsed field MUST NOT be Empty");
}
if (value == null) {
throw new IllegalArgumentException("NULL values are not supported by Representations");
}
URI property = sesameFactory.createURI(field);
Collection<Object> values = new ArrayList<Object>();
//process the parsed value with the Utility Method ->
// this converts Objects as defined in the specification
ModelUtils.checkValues(factory, value, values);
//We still need to implement support for specific types supported by this implementation
for (Object current : values) {
if (current instanceof Value) {
//native support for Sesame types!
addValue(property, (Value) current);
} else if (current instanceof RdfWrapper) {
//for Sesame RDF wrapper we can directly use the Value
addValue(property, ((RdfWrapper) current).getValue());
} else if (current instanceof Reference) {
addValue(property, sesameFactory.createURI(((Reference) current).getReference()));
} else if (current instanceof Text) {
addValue(property, sesameFactory.createLiteral(((Text) current).getText(), ((Text) current).getLanguage()));
} else {
//else add an typed Literal!
addValue(property, createTypedLiteral(current));
}
}
}
Aggregations