當前位置: 首頁>>代碼示例>>Java>>正文


Java ValueFactory.createBNode方法代碼示例

本文整理匯總了Java中org.openrdf.model.ValueFactory.createBNode方法的典型用法代碼示例。如果您正苦於以下問題:Java ValueFactory.createBNode方法的具體用法?Java ValueFactory.createBNode怎麽用?Java ValueFactory.createBNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.openrdf.model.ValueFactory的用法示例。


在下文中一共展示了ValueFactory.createBNode方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: cleanValue

import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
/**
 * "Cleans" a value for BigData
 *
 * @param v the value that needs cleaning
 * @param vf the value factory to make the new Value from
 * @return a value that won't make BigData bomb
 */
public static Value cleanValue( Value v, ValueFactory vf ) {
	Value newv;
	if ( v instanceof URI ) {
		newv = vf.createURI( v.stringValue() );
	}
	else if ( v instanceof BNode ) {
		newv = vf.createBNode( v.stringValue() );
	}
	else {
		Literal oldv = Literal.class.cast( v );
		if ( null != oldv.getLanguage() ) {
			newv = vf.createLiteral( oldv.stringValue(), oldv.getLanguage() );
		}
		else {
			newv = vf.createLiteral( oldv.stringValue(), oldv.getDatatype() );
		}
	}

	return newv;
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:28,代碼來源:EngineLoader.java

示例2: bnode

import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
/**
 * BNode factory
 * 
 * @return
 */
public BNode bnode() {
	try {
		RepositoryConnection con = therepository.getConnection();
		try {
			ValueFactory vf = con.getValueFactory();
			return vf.createBNode();
		} finally {
			con.close();
		}
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	}
}
 
開發者ID:dvcama,項目名稱:resource-to-sparqlresult,代碼行數:20,代碼來源:SimpleGraph.java

示例3: hasValueFromList

import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
private void hasValueFromList() {
	ValueFactory vf = getValueFactory();
	for (Statement st : ds.match(null, OWL.HASVALUE, null)) {
		Resource res = st.getSubject();
		Value obj = st.getObject();
		if (obj instanceof Resource) {
			BNode node = vf.createBNode();
			ds.add(res, OWL.ALLVALUESFROM, node);
			ds.add(node, RDF.TYPE, OWL.CLASS);
			BNode list = vf.createBNode();
			ds.add(node, OWL.ONEOF, list);
			ds.add(list, RDF.TYPE, RDF.LIST);
			ds.add(list, RDF.FIRST, obj);
			ds.add(list, RDF.REST, RDF.NIL);
			for (Value type : ds.match(obj, RDF.TYPE, null).objects()) {
				ds.add(node, RDFS.SUBCLASSOF, type);
			}
			for (Value prop : ds.match(res, OWL.ONPROPERTY, null).objects()) {
				for (Value range : ds.match(prop, RDFS.RANGE, null).objects()) {
					ds.add(node, RDFS.SUBCLASSOF, range);
				}
				for (Resource cls : ds.match(null, RDFS.SUBCLASSOF, res).subjects()) {
					for (Value sup : findSuperClasses(cls)) {
						if (!sup.equals(res) && !ds.match(sup, OWL.ONPROPERTY, prop).isEmpty()) {
							for (Value from : ds.match(sup, OWL.ALLVALUESFROM, null).objects()) {
								ds.add(node, RDFS.SUBCLASSOF, from);
							}
						}
					}
				}
			}
		}
	}
}
 
開發者ID:anno4j,項目名稱:anno4j,代碼行數:35,代碼來源:OwlNormalizer.java

示例4: getSesameResource

import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
public static org.openrdf.model.Resource getSesameResource(SubjectNode subject, ValueFactory valueFactory) {
    if (subject instanceof BlankNode) {
        return valueFactory.createBNode("" + subject.hashCode());
    }
    else { // must be a URIReference
        return getSesameURI((URIReference) subject, valueFactory);
    }
}
 
開發者ID:discoverygarden,項目名稱:trippi-sail,代碼行數:9,代碼來源:AbstractSesameSession.java

示例5: getSesameValue

import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
public static org.openrdf.model.Value getSesameValue(Node object, ValueFactory valueFactory) {
    if (object instanceof BlankNode) {
        return valueFactory.createBNode(String.valueOf(object.hashCode()));
    }
    else if (object instanceof URIReference) {
        return getSesameURI((URIReference) object, valueFactory);
    }
    else { // must be a Literal
        return getSesameLiteral((Literal) object, valueFactory);
    }
}
 
開發者ID:discoverygarden,項目名稱:trippi-sail,代碼行數:12,代碼來源:AbstractSesameSession.java

示例6: copyFromTdb

import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
private void copyFromTdb( Dataset dataset ) throws RepositoryException {
	ValueFactory vf = rc.getValueFactory();

	if ( dataset.supportsTransactions() ) {
		dataset.begin( ReadWrite.READ );
	}

	// Get model inside the transaction
	Model model = dataset.getDefaultModel();
	StmtIterator si = model.listStatements();

	try {
		rc.begin();
		while ( si.hasNext() ) {
			Statement stmt = si.next();
			com.hp.hpl.jena.rdf.model.Resource rsr = stmt.getSubject();
			Property pred = stmt.getPredicate();
			RDFNode val = stmt.getObject();
			Node valnode = val.asNode();
			
			Resource sub;
			try {
				sub = ( rsr.isAnon()
						? vf.createBNode( valnode.getBlankNodeLabel() )
						: vf.createURI( rsr.toString() ) );
			}
			catch ( UnsupportedOperationException uoo ) {
				log.warn( uoo, uoo );
				continue;
			}
			
			URI pred2 = vf.createURI( pred.toString() );
			Value val2;

			if ( val.isLiteral() ) {
				Literal lit = val.asLiteral();
				String dtstr = lit.getDatatypeURI();
				URI dt = ( null == dtstr ? null : vf.createURI( dtstr ) );
				String langstr = lit.getLanguage();

				if ( null == dt ) {
					if ( langstr.isEmpty() ) {
						val2 = vf.createLiteral( lit.toString() );
					}
					else {
						val2 = vf.createLiteral( lit.toString(), langstr );
					}
				}
				else {
					val2 = vf.createLiteral( lit.toString(), dt );
				}
			}
			else {
				if ( val.isAnon() ) {
					val2 = vf.createBNode( valnode.getBlankNodeLabel() );
				}
				else {
					val2 = vf.createURI( val.toString() );
				}
			}
			rc.add( sub, pred2, val2 );
		}
		rc.commit();
	}
	catch ( RepositoryException re ) {
		rc.rollback();
		throw re;
	}
	finally {
		if ( dataset.supportsTransactions() ) {
			dataset.end();
		}
	}
}
 
開發者ID:Ostrich-Emulators,項目名稱:semtool,代碼行數:75,代碼來源:JenaEngine.java

示例7: serializeValueComposite

import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
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 );
                }
            }
        } );
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:52,代碼來源:EntityStateSerializer.java

示例8: showProcessorWorks

import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
@Test
public void showProcessorWorks() throws Exception {
    // Enumerate some topics that will be re-used
    final String ryaInstance = UUID.randomUUID().toString();
    final UUID queryId = UUID.randomUUID();
    final String statementsTopic = KafkaTopics.statementsTopic(ryaInstance);
    final String resultsTopic = KafkaTopics.queryResultsTopic(queryId);

    // Create a topology for the Query that will be tested.
    final String sparql =
            "CONSTRUCT {" +
                "_:b a <urn:movementObservation> ; " +
                "<urn:location> ?location ; " +
                "<urn:direction> ?direction ; " +
            "}" +
            "WHERE {" +
                "?thing <urn:corner> ?location ." +
                "?thing <urn:compass> ?direction." +
            "}";

    final String bNodeId = UUID.randomUUID().toString();
    final TopologyBuilder builder = new TopologyFactory().build(sparql, statementsTopic, resultsTopic, () -> bNodeId);

    // Create the statements that will be input into the query.
    final ValueFactory vf = new ValueFactoryImpl();
    final List<VisibilityStatement> statements = new ArrayList<>();
    statements.add( new VisibilityStatement(
            vf.createStatement(vf.createURI("urn:car1"), vf.createURI("urn:compass"), vf.createURI("urn:NW")), "a") );
    statements.add( new VisibilityStatement(
            vf.createStatement(vf.createURI("urn:car1"), vf.createURI("urn:corner"), vf.createURI("urn:corner1")), "a") );

    // Make the expected results.
    final Set<VisibilityStatement> expected = new HashSet<>();
    final BNode blankNode = vf.createBNode(bNodeId);

    expected.add(new VisibilityStatement(vf.createStatement(blankNode, RDF.TYPE, vf.createURI("urn:movementObservation")), "a"));
    expected.add(new VisibilityStatement(vf.createStatement(blankNode, vf.createURI("urn:direction"), vf.createURI("urn:NW")), "a"));
    expected.add(new VisibilityStatement(vf.createStatement(blankNode, vf.createURI("urn:location"), vf.createURI("urn:corner1")), "a"));

    // Run the test.
    RyaStreamsTestUtil.runStreamProcessingTest(kafka, statementsTopic, resultsTopic, builder, statements, expected, VisibilityStatementDeserializer.class);
}
 
開發者ID:apache,項目名稱:incubator-rya,代碼行數:43,代碼來源:MultiProjectionProcessorIT.java

示例9: read

import org.openrdf.model.ValueFactory; //導入方法依賴的package包/類
@Nullable
private static Value read(final String[] nsArray, final ByteArrayInputStream stream) {

    try {
        final ValueFactory vf = Statements.VALUE_FACTORY;
        final int b = stream.read();
        final int hi = b & 0xE0;

        if (hi == HI_NULL) {
            return null;

        } else if (hi == HI_BNODE) {
            final byte[] id = new byte[(b & 0x1F) << 8 | stream.read()];
            ByteStreams.readFully(stream, id);
            return vf.createBNode(new String(id, Charsets.UTF_8));

        } else if (hi == HI_URI) {
            if ((b & 0x10) != 0) {
                final byte[] name = new byte[(b & 0xF) << 8 | stream.read()];
                final String ns = nsArray[stream.read()];
                ByteStreams.readFully(stream, name);
                return vf.createURI(ns, new String(name, Charsets.UTF_8));
            } else {
                final byte[] str = new byte[(b & 0xF) << 8 | stream.read()];
                ByteStreams.readFully(stream, str);
                return vf.createURI(new String(str, Charsets.UTF_8));
            }

        } else if (hi == HI_LITERAL) {
            byte[] lang = null;
            URI dt = null;
            if ((b & 0x10) != 0) {
                lang = new byte[b & 0xF];
                ByteStreams.readFully(stream, lang);
            } else if ((b & 0x1) != 0) {
                dt = DT_MAP.inverse().get(stream.read());
            } else if ((b & 0x2) != 0) {
                dt = (URI) read(nsArray, stream);
            }
            final byte[] label = new byte[stream.read() << 16 | stream.read() << 8
                    | stream.read()];
            ByteStreams.readFully(stream, label);
            final String labelStr = new String(label, Charsets.UTF_8);
            if (lang != null) {
                return vf.createLiteral(labelStr, new String(lang, Charsets.UTF_8));
            } else if (dt != null) {
                return vf.createLiteral(labelStr, dt);
            } else {
                return vf.createLiteral(labelStr);
            }

        } else {
            throw new Error("Invalid marker: " + b);
        }

    } catch (final IOException ex) {
        throw new Error(ex);
    }
}
 
開發者ID:dkmfbk,項目名稱:pikes,代碼行數:60,代碼來源:KeyQuadIndex.java


注:本文中的org.openrdf.model.ValueFactory.createBNode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。