Search in sources :

Example 81 with URI

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);
    }
}
Also used : Options(org.qi4j.api.value.ValueSerializer.Options) ValueType(org.qi4j.api.type.ValueType) Literal(org.openrdf.model.Literal) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI) ValueCompositeType(org.qi4j.api.type.ValueCompositeType)

Example 82 with URI

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;
}
Also used : Graph(org.openrdf.model.Graph) GraphImpl(org.openrdf.model.impl.GraphImpl) ValueFactory(org.openrdf.model.ValueFactory) URI(org.openrdf.model.URI)

Example 83 with URI

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);
    }
}
Also used : ValueFactory(org.openrdf.model.ValueFactory) AssociationDescriptor(org.qi4j.api.association.AssociationDescriptor) URI(org.openrdf.model.URI)

Example 84 with URI

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);
    }
}
Also used : Literal(org.openrdf.model.Literal) URI(org.openrdf.model.URI)

Example 85 with URI

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));
        }
    }
}
Also used : Reference(org.apache.stanbol.entityhub.servicesapi.model.Reference) ArrayList(java.util.ArrayList) Value(org.openrdf.model.Value) Text(org.apache.stanbol.entityhub.servicesapi.model.Text) URI(org.openrdf.model.URI)

Aggregations

URI (org.openrdf.model.URI)111 Test (org.junit.Test)28 SailConnection (org.openrdf.sail.SailConnection)25 Value (org.openrdf.model.Value)22 Statement (org.openrdf.model.Statement)21 NotifyingSailConnection (org.openrdf.sail.NotifyingSailConnection)21 Resource (org.openrdf.model.Resource)20 Literal (org.openrdf.model.Literal)14 ValueFactory (org.openrdf.model.ValueFactory)12 RepositoryException (org.openrdf.repository.RepositoryException)11 SailException (org.openrdf.sail.SailException)10 ShineRuntimeException (com.thoughtworks.studios.shine.ShineRuntimeException)8 Vertex (com.tinkerpop.blueprints.Vertex)7 HashSet (java.util.HashSet)7 Representation (org.apache.stanbol.entityhub.servicesapi.model.Representation)7 Model (org.openrdf.model.Model)7 URIImpl (org.openrdf.model.impl.URIImpl)7 Edge (com.tinkerpop.blueprints.Edge)6 BNode (org.openrdf.model.BNode)6 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)6