Java Code Examples for org.openrdf.model.Graph#getValueFactory()

The following examples show how to use org.openrdf.model.Graph#getValueFactory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityTypeSerializer.java    From attic-polygene-java with Apache License 2.0 6 votes vote down vote up
public Iterable<Statement> serialize( final EntityDescriptor entityDescriptor )
{
    Graph graph = new GraphImpl();
    ValueFactory values = graph.getValueFactory();
    URI entityTypeUri = values.createURI( Classes.toURI( entityDescriptor.types().findFirst().orElse( null ) ) );

    graph.add( entityTypeUri, Rdfs.TYPE, Rdfs.CLASS );
    graph.add( entityTypeUri, Rdfs.TYPE, OWL.CLASS );

    graph.add( entityTypeUri,
               PolygeneEntityType.TYPE,
               values.createLiteral( entityDescriptor.types().findFirst().get().toString() )
    );
    graph.add( entityTypeUri, PolygeneEntityType.QUERYABLE, values.createLiteral( entityDescriptor.queryable() ) );

    serializeMixinTypes( entityDescriptor, graph, entityTypeUri );

    serializePropertyTypes( entityDescriptor, graph, entityTypeUri );
    serializeAssociationTypes( entityDescriptor, graph, entityTypeUri );
    serializeManyAssociationTypes( entityDescriptor, graph, entityTypeUri );

    return graph;
}
 
Example 2
Source File: EntityTypeSerializer.java    From attic-polygene-java with Apache License 2.0 6 votes vote down vote up
private void serializeManyAssociationTypes( final EntityDescriptor entityDescriptor,
                                            final Graph graph,
                                            final URI entityTypeUri
)
{
    ValueFactory values = graph.getValueFactory();
    // ManyAssociations
    entityDescriptor.state().manyAssociations().forEach( manyAssociationType -> {
        URI associationURI = values.createURI( manyAssociationType.qualifiedName().toURI() );
        graph.add( associationURI, Rdfs.DOMAIN, entityTypeUri );

        graph.add( associationURI, Rdfs.TYPE, Rdfs.SEQ );

        URI associatedURI = values.createURI( manyAssociationType.qualifiedName().toURI() );
        graph.add( associationURI, Rdfs.RANGE, associatedURI );
        graph.add( associationURI, Rdfs.RANGE, XMLSchema.ANYURI );
    } );
}
 
Example 3
Source File: EntityTypeSerializer.java    From attic-polygene-java with Apache License 2.0 6 votes vote down vote up
private void serializeAssociationTypes( final EntityDescriptor entityDescriptor,
                                        final Graph graph,
                                        final URI entityTypeUri
)
{
    ValueFactory values = graph.getValueFactory();
    // Associations
    entityDescriptor.state().associations().forEach( associationType -> {
        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.apply( associationType.type() ) ) );
        graph.add( associationURI, Rdfs.RANGE, associatedURI );
        graph.add( associationURI, Rdfs.RANGE, XMLSchema.ANYURI );
    } );
}
 
Example 4
Source File: EntityTypeSerializer.java    From attic-polygene-java with Apache License 2.0 6 votes vote down vote up
private void serializePropertyTypes( final EntityDescriptor entityDescriptor,
                                     final Graph graph,
                                     final URI entityTypeUri
)
{
    ValueFactory values = graph.getValueFactory();

    // Properties
    entityDescriptor.state().properties().forEach( persistentProperty -> {
        URI propertyURI = values.createURI( persistentProperty.qualifiedName().toURI() );
        graph.add( propertyURI, Rdfs.DOMAIN, entityTypeUri );
        graph.add( propertyURI, Rdfs.TYPE, Rdfs.PROPERTY );

        // TODO Support more types
        URI type = dataTypes.get( persistentProperty.valueType().primaryType().getName() );
        if( type != null )
        {
            graph.add( propertyURI, Rdfs.RANGE, type );
        }
    } );
}
 
Example 5
Source File: EntityStateSerializer.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
public void serialize( final EntityState entityState,
                       final boolean includeNonQueryable,
                       final Graph graph
)
{
    ValueFactory values = graph.getValueFactory();
    EntityReference reference = entityState.entityReference();
    URI entityUri = createEntityURI( values, reference );

    graph.add( entityUri,
               Rdfs.TYPE,
               values.createURI(
                   Classes.toURI( entityState.entityDescriptor().types().findFirst().orElse( null ) ) ) );

    serializeProperties( entityState,
                         graph,
                         entityUri,
                         entityState.entityDescriptor(),
                         includeNonQueryable );

    serializeAssociations( entityState,
                           graph,
                           entityUri,
                           entityState.entityDescriptor().state().associations(),
                           includeNonQueryable );

    serializeManyAssociations( entityState,
                               graph,
                               entityUri,
                               entityState.entityDescriptor().state().manyAssociations(),
                               includeNonQueryable );
}
 
Example 6
Source File: EntityStateSerializer.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
private void serializeProperty( PropertyDescriptor persistentProperty, Object property,
                                Resource subject, Graph graph,
                                boolean includeNonQueryable )
{
    if( !( includeNonQueryable || persistentProperty.queryable() ) )
    {
        return; // Skip non-queryable
    }

    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 = serializer.serialize( Serializer.Options.NO_TYPE_INFO, property );
        final Literal object = valueFactory.createLiteral( stringProperty );
        graph.add( subject, predicate, object );
    }
}
 
Example 7
Source File: EntityStateSerializer.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
private void serializeAssociations( final EntityState entityState,
                                    final Graph graph, URI entityUri,
                                    final Stream<? extends AssociationDescriptor> associations,
                                    final boolean includeNonQueryable
)
{
    ValueFactory values = graph.getValueFactory();

    // Associations
    associations.filter( type -> includeNonQueryable || type.queryable() ).forEach(
        associationType ->
        {
            EntityReference associatedId
                = entityState
                .associationValueOf(
                    associationType
                        .qualifiedName() );
            if( associatedId != null )
            {
                URI assocURI = values
                    .createURI(
                        associationType
                            .qualifiedName()
                            .toURI() );
                URI assocEntityURI
                    = values.createURI(
                    associatedId
                        .toURI() );
                graph.add( entityUri,
                           assocURI,
                           assocEntityURI );
            }
        } );
}
 
Example 8
Source File: EntityTypeSerializer.java    From attic-polygene-java with Apache License 2.0 5 votes vote down vote up
private void serializeMixinTypes( final EntityDescriptor entityDescriptor,
                                  final Graph graph,
                                  final URI entityTypeUri
)
{
    ValueFactory values = graph.getValueFactory();

    entityDescriptor.mixinTypes().forEach( mixinType -> {
        graph.add( entityTypeUri, Rdfs.SUB_CLASS_OF, values.createURI( Classes.toURI( mixinType ) ) );
    } );
}
 
Example 9
Source File: Test_REST_ServiceDescription.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
	 * Request the SPARQL SERVICE DESCRIPTION for the end point.
	 */
	public void test_SERVICE_DESCRIPTION() throws Exception {

		final Graph g = RemoteRepository
				.asGraph(m_repo.getServiceDescription());

		final ValueFactory f = g.getValueFactory();

		// Verify the end point is disclosed.
		assertEquals(
				1,
				countMatches(g, null/* service */, SD.endpoint,
						f.createURI(m_repo.getSparqlEndPoint())));
//		            f.createURI(m_serviceURL + "/sparql")));

		// Verify description includes supported query and update languages.
		assertEquals(
				1,
				countMatches(g, null/* service */, SD.supportedLanguage,
						SD.SPARQL10Query));
		assertEquals(
				1,
				countMatches(g, null/* service */, SD.supportedLanguage,
						SD.SPARQL11Query));
		assertEquals(
				1,
				countMatches(g, null/* service */, SD.supportedLanguage,
						SD.SPARQL11Update));

		// Verify support for Basic Federated Query is disclosed.
		assertEquals(
				1,
				countMatches(g, null/* service */, SD.feature,
						SD.BasicFederatedQuery));

	}
 
Example 10
Source File: EntityStateSerializer.java    From attic-polygene-java with Apache License 2.0 4 votes vote down vote up
private void serializeValueComposite( Resource subject, URI predicate,
                                      ValueComposite value,
                                      ValueType valueType,
                                      Graph graph,
                                      String baseUri,
                                      boolean includeNonQueryable
)
{
    final ValueFactory valueFactory = graph.getValueFactory();
    BNode collection = valueFactory.createBNode();
    graph.add( subject, predicate, collection );

    ( (ValueCompositeType) valueType ).properties().forEach(
        persistentProperty ->
        {
            Object propertyValue
                = PolygeneAPI.FUNCTION_COMPOSITE_INSTANCE_OF
                .apply( value )
                .state()
                .propertyFor( persistentProperty.accessor() )
                .get();

            if( propertyValue != null )
            {
                ValueType type = persistentProperty
                    .valueType();
                if( type instanceof ValueCompositeType )
                {
                    URI pred = valueFactory.createURI( baseUri,
                                                       persistentProperty
                                                           .qualifiedName()
                                                           .name() );
                    serializeValueComposite( collection, pred,
                                             (ValueComposite) propertyValue,
                                             type, graph,
                                             baseUri
                                             + persistentProperty
                                                 .qualifiedName()
                                                 .name() + "/",
                                             includeNonQueryable );
                }
                else
                {
                    serializeProperty( persistentProperty,
                                       propertyValue,
                                       collection, graph,
                                       includeNonQueryable );
                }
            }
        } );
}
 
Example 11
Source File: EntityStateSerializer.java    From attic-polygene-java with Apache License 2.0 4 votes vote down vote up
private void serializeManyAssociations( final EntityState entityState,
                                        final Graph graph,
                                        final URI entityUri,
                                        final Stream<? extends AssociationDescriptor> associations,
                                        final boolean includeNonQueryable
)
{
    ValueFactory values = graph.getValueFactory();

    // Many-Associations
    associations.filter( type -> includeNonQueryable || type.queryable() ).forEach(
        associationType ->
        {
            BNode collection = values
                .createBNode();
            graph.add( entityUri, values
                           .createURI(
                               associationType
                                   .qualifiedName()
                                   .toURI() ),
                       collection );
            graph.add( collection,
                       Rdfs.TYPE,
                       Rdfs.SEQ );

            ManyAssociationState
                associatedIds
                = entityState
                .manyAssociationValueOf(
                    associationType
                        .qualifiedName() );
            for( EntityReference associatedId : associatedIds )
            {
                URI assocEntityURI
                    = values.createURI(
                    associatedId
                        .toURI() );
                graph.add( collection,
                           Rdfs.LIST_ITEM,
                           assocEntityURI );
            }
        } );
}
 
Example 12
Source File: SD.java    From database with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 
 * @param g
 *            Where to assemble the description.
 * @param tripleStore
 *            The KB instance to be described.
 * @param serviceURIs
 *            One or more service end points for that KB instance.
 * 
 * @see #describeService()
 */
public SD(final Graph g, final AbstractTripleStore tripleStore,
        final String... serviceURI) {

    if (g == null)
        throw new IllegalArgumentException();

    if (tripleStore == null)
        throw new IllegalArgumentException();
    
    if (serviceURI == null)
        throw new IllegalArgumentException();

    if (serviceURI.length == 0)
        throw new IllegalArgumentException();

    for (String s : serviceURI)
        if (s == null)
            throw new IllegalArgumentException();

    this.g = g;
    
    this.tripleStore = tripleStore;
    
    this.serviceURI = serviceURI;
    
    this.f = g.getValueFactory();
    
    aService = f.createBNode("service");

    aDefaultDataset = f.createBNode("defaultDataset");
    
}
 
Example 13
Source File: VoID.java    From database with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 
 * @param g
 *            Where to assemble the description.
 * @param tripleStore
 *            The KB instance to be described.
 * @param serviceURI
 *            The SPARQL service end point.
 * @param aDefaultDataset
 *            The data set identifier that will be used on the description
 *            (the bigdata namespace of the dataset is obtained from the
 *            <i>tripleStore</i>).
 */
public VoID(final Graph g, final AbstractTripleStore tripleStore,
        final String[] serviceURI, final Resource aDataset) {

    if (g == null)
        throw new IllegalArgumentException();

    if (tripleStore == null)
        throw new IllegalArgumentException();
    
    if (serviceURI == null)
        throw new IllegalArgumentException();

    if (serviceURI.length == 0)
        throw new IllegalArgumentException();

    for (String s : serviceURI)
        if (s == null)
            throw new IllegalArgumentException();
    
    if (aDataset == null)
        throw new IllegalArgumentException();

    this.g = g;
    
    this.tripleStore = tripleStore;
    
    this.serviceURI = serviceURI;
    
    this.f = g.getValueFactory();
    
    this.aDataset = aDataset;

    this.aDefaultGraph = f.createBNode("defaultGraph");
    
}