本文整理汇总了Java中com.hp.hpl.jena.rdf.model.RDFNode类的典型用法代码示例。如果您正苦于以下问题:Java RDFNode类的具体用法?Java RDFNode怎么用?Java RDFNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RDFNode类属于com.hp.hpl.jena.rdf.model包,在下文中一共展示了RDFNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeCategories
import com.hp.hpl.jena.rdf.model.RDFNode; //导入依赖的package包/类
public Set<String> initializeCategories() {
Model model = ModelFactory.createDefaultModel();
model.read("/home/zwicklbauer/HDTGeneration/skos_categories_en.nt");
StmtIterator it = model.listStatements();
Set<String> set = new HashSet<String>();
System.out.println("Los gehts");
while (it.hasNext()) {
Statement s = it.next();
Resource r = s.getSubject();
Property p = s.getPredicate();
RDFNode n = s.getObject();
if (p.getURI().equalsIgnoreCase(
"http://www.w3.org/2004/02/skos/core#broader")
&& n.isResource()) {
Resource target = n.asResource();
if(!hasSubCategory(target.getURI()))
set.add(target.getURI());
if(!hasSubCategory(r.getURI()))
set.add(r.getURI());
}
}
return set;
}
示例2: getEventFromRDFNodes
import com.hp.hpl.jena.rdf.model.RDFNode; //导入依赖的package包/类
/**
* Parse specific nodes in order to create an {@link Event} object.
* Check the date from startDate and endDate RDF nodes.
* Retrieve the label and description from labelNode and descriptionNode.
*
* @param latitudeNode RDF formatted latitude node
* @param longitudeNode RDF formatted longitude node
* @param startDate filter start date
* @param endDate filter end date
* @param descriptionNode contains the event
* @param label tags
* @return null if the checkRDFNodes is false or a ParseException has been caught, else the {@link Event} object
* @see LatLong
* @see Event
*/
private static Event getEventFromRDFNodes(RDFNode latitudeNode, RDFNode longitudeNode, RDFNode startDate, RDFNode endDate, RDFNode descriptionNode, String label) {
if (checkRDFNodes(latitudeNode, longitudeNode, startDate, endDate, descriptionNode)) {
try {
LatLong latLong = getLatlongFromRDFNodes(latitudeNode, longitudeNode);
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date start = dateFormat.parse(startDate.asLiteral().getString());
Date end = dateFormat.parse(endDate.asLiteral().getString());
String desc = descriptionNode.asLiteral().getString();
return new Event(latLong, start, end, desc, label);
} catch (ParseException e) {
LOGGER.error(e.getMessage());
return null;
}
}
return null;
}
示例3: parse
import com.hp.hpl.jena.rdf.model.RDFNode; //导入依赖的package包/类
/**
* Parse RDF input as string
*
* @param input RDF values as String
* @return an {@link Request} object which contains information about latitude, longitude and date
* @throws IllegalStateException if RDF is not literal
* @throws NullPointerException if input is null
*/
public static Request parse(String input) {
Objects.requireNonNull(input);
Model model = ModelFactory.createDefaultModel();
model.read(new ByteArrayInputStream(input.getBytes()), null, "TURTLE");
Map<String, Object> map = new HashMap<>();
model.listStatements().forEachRemaining(statement -> {
RDFNode rdfNode = statement.getObject();
if (rdfNode.isLiteral()) {
try {
map.put(statement.getPredicate().getLocalName(), statement.getObject().asLiteral().getValue());
} catch (Exception e) {
LOGGER.error("RDF statement is not literal");
throw new IllegalStateException(e.getMessage());
}
}
});
model.close();
return getDataFromMap(map);
}
示例4: executeQueryForLong
import com.hp.hpl.jena.rdf.model.RDFNode; //导入依赖的package包/类
public static long executeQueryForLong(String queryString, String serviceEndpoint, String var) {
logger.debug("Executing query: {}", queryString);
//Execute the query
Map<String, RDFNode> nodeMap = executeQueryForMap(queryString, serviceEndpoint, Sets.newHashSet(var));
RDFNode rdfNode = nodeMap.get(var);
if (rdfNode == null) {
throw new IllegalStateException(String.format("The result does not have a binding for the variable '%s' ", var));
}
if (rdfNode.isLiteral()) {
return rdfNode.asLiteral().getLong();
} else {
throw new IllegalStateException(String.format("The binding for the variable '%s' is not a literal", var));
}
}
示例5: main
import com.hp.hpl.jena.rdf.model.RDFNode; //导入依赖的package包/类
public static void main(String[] args) {
String query = QueryCollection.TOTAL_TRIPLES;
try (QueryExecution qexec = QueryExecutionFactory.sparqlService("http://localhost:3030/ldqm/query", query)) {
{
ResultSet results = qexec.execSelect();
// We only return the first solutions, may be a map of map
for (; results.hasNext(); ) {
QuerySolution soln = results.nextSolution();
Map<String, RDFNode> resultsMap = new HashMap<String, RDFNode>();
if (soln.contains("c")) {
System.out.println(soln.get("c").asLiteral().getInt());
}
}
}
}
}
示例6: executeQueryForList
import com.hp.hpl.jena.rdf.model.RDFNode; //导入依赖的package包/类
public static List<RDFNode> executeQueryForList(String queryString, String serviceEndpoint, String var) {
List<RDFNode> resultsList = new ArrayList<>();
Query query = QueryFactory.create(queryString);
try (QueryExecution qexec = QueryExecutionFactory.sparqlService(serviceEndpoint, query)) {
{
ResultSet results = qexec.execSelect();
// collect all the values
for (; results.hasNext(); ) {
QuerySolution soln = results.nextSolution();
if (soln.contains(var)) {
resultsList.add(soln.get(var));
}
}
return resultsList;
}
}
}
示例7: nodeType
import com.hp.hpl.jena.rdf.model.RDFNode; //导入依赖的package包/类
private String nodeType(RDFNode node) {
if (node.isURIResource()) {
return "IRI";
}
if (node.isAnon()) {
return "blank node";
}
if (!"".equals(node.asLiteral().getLanguage())) {
return "language-tagged string";
}
if (node.asLiteral().getDatatypeURI() == null) {
return "plain literal";
}
if (XSD.xstring.getURI().equals(node.asLiteral().getDatatypeURI())) {
return "string literal";
}
return "non-string typed literal";
}
示例8: Message
import com.hp.hpl.jena.rdf.model.RDFNode; //导入依赖的package包/类
/**
* @param problem
* @param subject May be null
* @param predicates May be null
* @param objects May be null
*/
public Message(Problem problem, Resource subject,
Property[] predicates, RDFNode[] objects) {
this.problem = problem;
this.subject = subject;
this.predicates =
predicates == null
? Collections.<Property>emptyList()
: Arrays.asList(predicates);
Collections.sort(this.predicates, RDFComparator.getRDFNodeComparator());
this.objects =
objects == null
? Collections.<RDFNode>emptyList()
: Arrays.asList(objects);
Collections.sort(this.objects, RDFComparator.getRDFNodeComparator());
this.detailCode = null;
this.details = null;
this.cause = null;
}
示例9: toTurtle
import com.hp.hpl.jena.rdf.model.RDFNode; //导入依赖的package包/类
private String toTurtle(RDFNode r) {
if (r.isURIResource()) {
return PrettyPrinter.qNameOrURI(relativize(r.asResource().getURI()), prefixes);
} else if (r.isLiteral()) {
StringBuffer result = new StringBuffer(quote(r.asLiteral().getLexicalForm()));
if (!"".equals(r.asLiteral().getLanguage())) {
result.append("@");
result.append(r.asLiteral().getLanguage());
} else if (r.asLiteral().getDatatype() != null) {
result.append("^^");
result.append(toTurtle(ResourceFactory.createResource(r.asLiteral().getDatatypeURI())));
}
return result.toString();
} else {
if (!blankNodeMap.containsKey(r)) {
blankNodeMap.put(r.asResource(), "_:b" + blankNodeCounter++);
}
return blankNodeMap.get(r);
}
}
示例10: printTranslationTable
import com.hp.hpl.jena.rdf.model.RDFNode; //导入依赖的package包/类
private void printTranslationTable(TranslationTable table) {
printMapObject(table, D2RQ.TranslationTable);
out.printURIProperty(D2RQ.href, table.getHref());
out.printProperty(D2RQ.javaClass, table.getJavaClass());
Iterator<Translation> it = table.getTranslations().iterator();
List<Map<Property,RDFNode>> values = new ArrayList<Map<Property,RDFNode>>();
while (it.hasNext()) {
Translation translation = it.next();
Map<Property,RDFNode> r = new LinkedHashMap<Property,RDFNode>();
r.put(D2RQ.databaseValue,
ResourceFactory.createPlainLiteral(translation.dbValue()));
r.put(D2RQ.rdfValue,
ResourceFactory.createPlainLiteral(translation.rdfValue()));
values.add(r);
}
out.printCompactBlankNodeProperties(D2RQ.translation, values);
}
示例11: compare
import com.hp.hpl.jena.rdf.model.RDFNode; //导入依赖的package包/类
public int compare(RDFNode n1, RDFNode n2) {
if (n1.isURIResource()) {
if (!n2.isURIResource()) return -1;
return n1.asResource().getURI().compareTo(n2.asResource().getURI());
}
if (n1.isAnon()) {
if (n2.isURIResource()) return 1;
if (n2.isLiteral()) return -1;
return n1.asResource().getId().getLabelString().compareTo(n2.asResource().getId().getLabelString());
}
if (!n2.isLiteral()) return 1;
int cmpLex = n1.asLiteral().getLexicalForm().compareTo(n2.asLiteral().getLexicalForm());
if (cmpLex != 0) return cmpLex;
if (n1.asLiteral().getDatatypeURI() == null) {
if (n2.asLiteral().getDatatypeURI() != null) return -1;
return n1.asLiteral().getLanguage().compareTo(n2.asLiteral().getLanguage());
}
if (n2.asLiteral().getDatatypeURI() == null) return 1;
return n1.asLiteral().getDatatypeURI().compareTo(n2.asLiteral().getDatatypeURI());
}
示例12: createPredicateObjectMap
import com.hp.hpl.jena.rdf.model.RDFNode; //导入依赖的package包/类
private PredicateObjectMap createPredicateObjectMap(Resource r) {
PredicateObjectMap result = new PredicateObjectMap();
result.getPredicateMaps().addAll(getResources(r, RR.predicateMap));
for (RDFNode predicate: getRDFNodes(r, RR.predicate)) {
result.getPredicates().add(ConstantShortcut.create(predicate));
}
result.getObjectMaps().addAll(getResources(r, RR.objectMap));
for (RDFNode object: getRDFNodes(r, RR.object)) {
result.getObjects().add(ConstantShortcut.create(object));
}
result.getGraphMaps().addAll(getResources(r, RR.graphMap));
for (RDFNode graph: getRDFNodes(r, RR.graph)) {
result.getGraphs().add(ConstantShortcut.create(graph));
}
return result;
}
示例13: getRDFNodes
import com.hp.hpl.jena.rdf.model.RDFNode; //导入依赖的package包/类
public List<RDFNode> getRDFNodes(Resource r, Property p, NodeType acceptableNodes) {
List<RDFNode> result = new ArrayList<RDFNode>();
StmtIterator it = r.listProperties(p);
while (it.hasNext()) {
Statement stmt = it.next();
remainingTriples.remove(stmt);
if (acceptableNodes.isTypeOf(stmt.getObject())) {
result.add(stmt.getObject());
} else {
if (acceptableNodes.coerce(stmt.getObject()) != null) {
result.add(acceptableNodes.coerce(stmt.getObject()));
}
report.report(acceptableNodes.ifNot, r, p, stmt.getObject());
}
}
Collections.sort(result, RDFComparator.getRDFNodeComparator());
return result;
}
示例14: solutionToMap
import com.hp.hpl.jena.rdf.model.RDFNode; //导入依赖的package包/类
public static Map<String,RDFNode> solutionToMap(QuerySolution solution, List<String> variables) {
Map<String,RDFNode> result = new HashMap<String,RDFNode>();
Iterator<String> it = solution.varNames();
while (it.hasNext()) {
String variableName = it.next();
if (!variables.contains(variableName)) {
continue;
}
RDFNode value = solution.get(variableName);
int size = value.toString().length();
if (size>250) {
bigStringInResultLogger.debug("Big string (" + size + ") in resultBinding:\n" + value);
}
result.put(variableName,value);
}
return result;
}
示例15: getClassLabels
import com.hp.hpl.jena.rdf.model.RDFNode; //导入依赖的package包/类
/**
* If class has a label AbraCadabraQualityPerformance --> Abra Cadabra --> abra cadabra : will be returned as a label in the set.
*
* @param ocls
* @return
*/
public Set<String> getClassLabels(OntClass ocls) {
String name = ocls.getLocalName();
ExtendedIterator<RDFNode> iterator = ocls.listLabels(null);
List<String> labels = new ArrayList<String>(3);
while (iterator.hasNext()) {
labels.add(iterator.next().asLiteral().getLexicalForm());
}
// get trimmed name,labels then split camel case.
name = trimName(name);
name = LingUtil.splitCamelCase(name).toLowerCase();
for (int i = 0; i < labels.size(); i++) {
labels.set(i, LingUtil.splitCamelCase(trimName(labels.get(i))).toLowerCase());//trim then split camel case . then make lowercase
}
Set<String> lbls = new HashSet<String>(3);
lbls.add(name);
lbls.addAll(labels);
return lbls;
}