本文整理匯總了Java中org.apache.jena.rdf.model.RDFNode類的典型用法代碼示例。如果您正苦於以下問題:Java RDFNode類的具體用法?Java RDFNode怎麽用?Java RDFNode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
RDFNode類屬於org.apache.jena.rdf.model包,在下文中一共展示了RDFNode類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: fillTrie
import org.apache.jena.rdf.model.RDFNode; //導入依賴的package包/類
@Override
protected void fillTrie(Logger logger, Trie<Resource> trie, Corpus corpus) throws IOException, ModuleException {
Model model = createModel(logger);
Property typeProp = model.getProperty("http://www.w3.org/1999/02/22-rdf-syntax-ns#type");
Property[] labelPropertyProps = getProperties(model, labelURIs);
int nEntries = 0;
for (String resourceTypeURI : resourceTypeURIs) {
Property resourceType = model.getProperty(model.expandPrefix(resourceTypeURI));
for (Resource res : Iterators.loop(model.listSubjectsWithProperty(typeProp , resourceType))) {
if (res.isAnon()) {
continue;
}
for (Property prop : labelPropertyProps) {
for (RDFNode node : Iterators.loop(model.listObjectsOfProperty(res, prop))) {
String label = getNodeValue(node);
trie.addEntry(label, res);
nEntries++;
}
}
}
}
logger.info("Entries: " + nEntries);
}
示例2: getProperties
import org.apache.jena.rdf.model.RDFNode; //導入依賴的package包/類
private static List<Pair<String, String>> getProperties(String uri) {
List<Pair<String, String>> results = new ArrayList<>();
String sparqlQuery = "select ?r ?y where {<" + uri + "> ?r ?y}";
//System.out.println(sparqlQuery);
QueryExecution e = QueryExecutionFactory.sparqlService(ENDPOINT, sparqlQuery);
ResultSet rs = e.execSelect();
while (rs.hasNext()) {
QuerySolution nextSolution = rs.nextSolution();
RDFNode ynode = nextSolution.get("y");
if (ynode.isResource()) {
results.add(Pair.of(nextSolution.getResource("r").getURI(), nextSolution.getResource("y").getURI()));
} else {
results.add(Pair.of(nextSolution.getResource("r").getURI(), nextSolution.getLiteral("y").getString().replaceAll("\\n+", " ")));
}
}
e.close();
return results;
}
示例3: getJenaModel
import org.apache.jena.rdf.model.RDFNode; //導入依賴的package包/類
private Model getJenaModel(@NonNull org.eclipse.rdf4j.model.Model model) {
Model jenaModel = ModelFactory.createDefaultModel();
java.util.Iterator<org.eclipse.rdf4j.model.Statement> iterator = model.iterator();
while (iterator.hasNext()) {
org.eclipse.rdf4j.model.Statement rdf4jStatement = iterator.next();
// create resource / subject
Resource resource = rdf4jResourceToJenaResource(jenaModel, rdf4jStatement.getSubject());
// create property / predicate
Property property =
rdf4jPropertyToJenaProperty(jenaModel, (SimpleIRI) rdf4jStatement.getPredicate());
// create rdfnode / object
RDFNode node = rdf4jValueToJenaRdfNode(jenaModel, rdf4jStatement.getObject());
Statement statement = ResourceFactory.createStatement(resource, property, node);
jenaModel.add(statement);
}
return jenaModel;
}
示例4: getLabelFromLinkedData
import org.apache.jena.rdf.model.RDFNode; //導入依賴的package包/類
/**
* Dereference the IRI and look for label property value.
* @param iri the IRI
* @return the label if exist, otherwise <code>null</code>
*/
private String getLabelFromLinkedData(String iri){
logger.debug("Get label for " + iri + " from Linked Data...");
try {
// 1. get triples for the IRI by sending a Linked Data request
Model model = uriDereferencer.dereference(iri);
// 2. check if we find a label in the triples
for (String labelProperty : labelProperties) {
for(Statement st : model.listStatements(model.getResource(iri), model.getProperty(labelProperty), (RDFNode)null).toList()){
Literal literal = st.getObject().asLiteral();
// language check
String language = literal.getLanguage();
if(language != null && language.equals(this.language)){
return literal.getLexicalForm();
}
}
}
} catch (DereferencingFailedException e) {
logger.error(e.getMessage(), e);
}
return null;
}
示例5: getResultSetAsStringList
import org.apache.jena.rdf.model.RDFNode; //導入依賴的package包/類
static List<String> getResultSetAsStringList(ResultSet resultSet, String variableName, boolean literalRequired) {
List<String> resultStrings = new ArrayList<>();
RDFNode node;
if (resultSet != null) {
while (resultSet.hasNext()) {
QuerySolution result = resultSet.next();
if (result != null) {
node = result.get(variableName);
if (literalRequired) {
String literal = getStringLiteral(node);
if (literal != null) {
resultStrings.add(literal);
}
} else {
if (node != null) {
resultStrings.add(node.toString());
}
}
}
}
}
return resultStrings;
}
示例6: makeSampleModel
import org.apache.jena.rdf.model.RDFNode; //導入依賴的package包/類
private static Model makeSampleModel() {
String BASE = "http://example/";
Model model = ModelFactory.createDefaultModel();
model.setNsPrefix("", BASE);
Resource r1 = model.createResource(BASE + "r1");
Resource r2 = model.createResource(BASE + "r2");
Property p1 = model.createProperty(BASE + "p");
Property p2 = model.createProperty(BASE + "p2");
RDFNode v1 = model.createTypedLiteral("1", XSDDatatype.XSDinteger);
RDFNode v2 = model.createTypedLiteral("2", XSDDatatype.XSDinteger);
r1.addProperty(p1, v1).addProperty(p1, v2);
r1.addProperty(p2, v1).addProperty(p2, v2);
r2.addProperty(p1, v1).addProperty(p1, v2);
return model;
}
示例7: queryData
import org.apache.jena.rdf.model.RDFNode; //導入依賴的package包/類
public static List<String> queryData(String query){
Dataset db = TDBFactory.createDataset("temp/dataset");
db.begin(ReadWrite.READ);
Model model = db.getDefaultModel();
Query q = QueryFactory.create(query);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet results = qexec.execSelect();
List<String> answer = new ArrayList<String>();
while(results.hasNext()){
QuerySolution t = results.nextSolution();
RDFNode x = t.get("x");
String s = x.toString();
System.out.println(s);
answer.add(s.substring(7));
}
qexec.close();
db.close();
return answer;
}
示例8: listSystemBeans
import org.apache.jena.rdf.model.RDFNode; //導入依賴的package包/類
public static List<SystemBean> listSystemBeans(Model model, Resource involvingResource) {
List<SystemBean> systems = new ArrayList<>();
if (model == null) {
return systems;
}
// iterate over all systems
NodeIterator systemIterator = model.listObjectsOfProperty(involvingResource, HOBBIT.involvesSystemInstance);
RDFNode node;
while (systemIterator.hasNext()) {
node = systemIterator.next();
if (node.isResource()) {
systems.add(getSystemBean(model, node.asResource()));
}
}
return systems;
}
示例9: createParamValueBeans
import org.apache.jena.rdf.model.RDFNode; //導入依賴的package包/類
private static void createParamValueBeans(Model model, Resource taskResource, NodeIterator parameterIterator,
Map<String, ConfigurationParamValueBean> parameters) {
RDFNode node;
Resource parameter;
Property paraProp;
String parameterUri;
while (parameterIterator.hasNext()) {
node = parameterIterator.next();
if (node.isResource()) {
parameter = node.asResource();
parameterUri = parameter.getURI();
paraProp = model.getProperty(parameterUri);
if (model.contains(taskResource, paraProp) && !parameters.containsKey(parameterUri)) {
ConfigurationParamValueBean paramBean = new ConfigurationParamValueBean();
paramBean.setId(parameterUri);
paramBean.setValue(RdfHelper.getStringValue(model, taskResource, paraProp));
parameters.put(parameterUri, paramBean);
}
}
}
}
示例10: filterBinaryReferences
import org.apache.jena.rdf.model.RDFNode; //導入依賴的package包/類
/**
* Filter out the binary resource references from the model
* @param uri the URI for the resource
* @param model the RDF Model of the resource
* @return the RDF model with no binary references
* @throws FcrepoOperationFailedException
* @throws IOException
*/
private void filterBinaryReferences(final URI uri, final Model model) throws IOException,
FcrepoOperationFailedException {
final List<Statement> removeList = new ArrayList<>();
for (final StmtIterator it = model.listStatements(); it.hasNext();) {
final Statement s = it.nextStatement();
final RDFNode obj = s.getObject();
if (obj.isResource() && obj.toString().startsWith(repositoryRoot.toString())
&& !s.getPredicate().toString().equals(REPOSITORY_NAMESPACE + "hasTransactionProvider")) {
try (final FcrepoResponse resp = client().head(URI.create(obj.toString())).disableRedirects()
.perform()) {
checkValidResponse(resp, URI.create(obj.toString()), config.getUsername());
final List<URI> linkHeaders = resp.getLinkHeaders("type");
if (linkHeaders.contains(binaryURI)) {
removeList.add(s);
}
}
}
}
model.remove(removeList);
}
示例11: getTriples
import org.apache.jena.rdf.model.RDFNode; //導入依賴的package包/類
/**
* Gets all triples for resource r and property p. If outgoing is true it
* returns all triples with <r,p,o>, else <s,p,r>
*
* @param r
* the resource
* @param p
* the property
* @param outgoing
* whether to get outgoing or ingoing triples
* @return A set of triples
*/
public Set<Triple> getTriples(Resource r, Property p, boolean outgoing) {
Set<Triple> result = new HashSet<Triple>();
try {
String q;
if (outgoing) {
q = "SELECT ?o where { <" + r.getURI() + "> <" + p.getURI() + "> ?o." + "?o rdfs:label []}";
} else {
q = "SELECT ?o where { ?o <" + p.getURI() + "> <" + r.getURI() + ">." + "?o rdfs:label []}";
}
q += " LIMIT " + maxShownValuesPerProperty + 1;
QueryExecution qe = qef.createQueryExecution(q);
ResultSet results = qe.execSelect();
if (results.hasNext()) {
while (results.hasNext()) {
RDFNode n = results.next().get("o");
result.add(Triple.create(r.asNode(), p.asNode(), n.asNode()));
}
}
qe.close();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
示例12: DBpediaGenderDictionary
import org.apache.jena.rdf.model.RDFNode; //導入依賴的package包/類
public DBpediaGenderDictionary() {
Model model = ModelFactory.createDefaultModel();
Literal maleLit = model.createLiteral(VALUE_MALE, "en");
Literal femaleLit = model.createLiteral(VALUE_FEMALE, "en");
RDFDataMgr.read(model, getClass().getClassLoader().getResourceAsStream(GENDER_FILE_LOCATION), Lang.TURTLE);
StmtIterator iter = model.listStatements(null, model.createProperty(GENDER_PROPERTY), (RDFNode) null);
while (iter.hasNext()) {
Statement st = iter.next();
Literal lit = st.getObject().asLiteral();
if (lit.equals(maleLit)) {
male.add(st.getSubject().getURI());
} else if (lit.equals(femaleLit)) {
female.add(st.getSubject().getURI());
}
}
}
示例13: toRDFNode
import org.apache.jena.rdf.model.RDFNode; //導入依賴的package包/類
public static RDFNode toRDFNode(String value) {
if (isURI(value)) {
return ResourceFactory.createResource(value);
} else if (NumberUtils.isNumber(value)) {
if (value.contains(".")) {
return ResourceFactory.createTypedLiteral(value, XSDDatatype.XSDdouble);
}
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
return ResourceFactory.createTypedLiteral(value, XSDDatatype.XSDboolean);
} else {
return ResourceFactory.createTypedLiteral(value, XSDDatatype.XSDinteger);
}
} else {
return ResourceFactory.createTypedLiteral(value, XSDDatatype.XSDstring);
}
}
示例14: applyDefaults
import org.apache.jena.rdf.model.RDFNode; //導入依賴的package包/類
public TemplateCall applyDefaults()
{
Iterator<Parameter> paramIt = getTemplate().getParameters().values().iterator();
while (paramIt.hasNext())
{
Parameter param = paramIt.next();
RDFNode defaultValue = param.getDefaultValue();
if (defaultValue != null && !hasArgument(param.getPredicate()))
{
Resource arg = getResource().getModel().createResource().
addProperty(RDF.type, param).
addLiteral(LDT.paramName, param.getPredicate().getLocalName()).
addProperty(SPL.predicate, param.getPredicate()).
addProperty(RDF.value, defaultValue);
arg(arg);
}
}
return this;
}
示例15: convertListToResource
import org.apache.jena.rdf.model.RDFNode; //導入依賴的package包/類
public List<RDFNode> convertListToResource(IfcCollectionValue<? extends IfcValue> listValue, IfcCollectionTypeInfo collectionTypeInfo,
Resource parentResource, long childNodeCount)
{
final String convertCollectionsTo = context.getConversionParams().convertCollectionsTo();
switch (convertCollectionsTo) {
case Ifc2RdfConversionParams.VALUE_DRUMMOND_LIST:
return convertListToDrummondList(listValue, collectionTypeInfo, parentResource, childNodeCount);
case Ifc2RdfConversionParams.VALUE_OLO_SIMILAR_LIST:
return convertListToOloSimilarList(listValue, collectionTypeInfo, parentResource, childNodeCount);
default:
throw new NotImplementedException("Unknown collection type");
}
}