当前位置: 首页>>代码示例>>Java>>正文


Java RDFNode类代码示例

本文整理汇总了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;
}
 
开发者ID:quhfus,项目名称:DoSeR,代码行数:25,代码来源:DbpediaGraphModification.java

示例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;
}
 
开发者ID:IKB4Stream,项目名称:IKB4Stream,代码行数:32,代码来源:DBpediaProducerConnector.java

示例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);
}
 
开发者ID:IKB4Stream,项目名称:IKB4Stream,代码行数:30,代码来源:RDFParser.java

示例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));
        }

    }
 
开发者ID:nandana,项目名称:ld-sniffer,代码行数:20,代码来源:SparqlUtils.java

示例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());
                        }
                    }
                }
            }
        }
 
开发者ID:nandana,项目名称:ld-sniffer,代码行数:21,代码来源:SPARQLQuery.java

示例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;
            }
        }
    }
 
开发者ID:nandana,项目名称:ld-sniffer,代码行数:23,代码来源:LDResourceExtractor.java

示例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";
}
 
开发者ID:d2rq,项目名称:r2rml-kit,代码行数:19,代码来源:PlainTextMessageRenderer.java

示例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;
}
 
开发者ID:d2rq,项目名称:r2rml-kit,代码行数:25,代码来源:Message.java

示例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);
	}
}
 
开发者ID:d2rq,项目名称:r2rml-kit,代码行数:21,代码来源:PrettyTurtleWriter.java

示例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);
}
 
开发者ID:d2rq,项目名称:r2rml-kit,代码行数:18,代码来源:D2RQWriter.java

示例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()); 
}
 
开发者ID:d2rq,项目名称:r2rml-kit,代码行数:21,代码来源:RDFComparator.java

示例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;
}
 
开发者ID:d2rq,项目名称:r2rml-kit,代码行数:17,代码来源:R2RMLReader.java

示例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;
}
 
开发者ID:d2rq,项目名称:r2rml-kit,代码行数:19,代码来源:R2RMLReader.java

示例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;
}
 
开发者ID:aitoralmeida,项目名称:c4a_data_repository,代码行数:18,代码来源:QueryLanguageTestFramework.java

示例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;
}
 
开发者ID:sasinda,项目名称:OntologyBasedInormationExtractor,代码行数:26,代码来源:LinguisticEnhancer.java


注:本文中的com.hp.hpl.jena.rdf.model.RDFNode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。