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


Java Statement類代碼示例

本文整理匯總了Java中com.hp.hpl.jena.rdf.model.Statement的典型用法代碼示例。如果您正苦於以下問題:Java Statement類的具體用法?Java Statement怎麽用?Java Statement使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Statement類屬於com.hp.hpl.jena.rdf.model包,在下文中一共展示了Statement類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: initializeCategories

import com.hp.hpl.jena.rdf.model.Statement; //導入依賴的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: expandSubClasses

import com.hp.hpl.jena.rdf.model.Statement; //導入依賴的package包/類
private List<Statement> expandSubClasses(Model model){
	List<Statement> stmts = new ArrayList<Statement>();
	
	
	String sparql = "PREFIX rdfs: <" + RDFS.getURI() + ">"
			+ "SELECT DISTINCT ?class ?synonym "
			+ "WHERE { "
			+ "?class rdfs:subClassOf+ ?subClass . "
			+ "?subClass <" + synonym + "> ?synonym"
			+ "}";
	
	Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
	QueryExecution queryExecution = QueryExecutionFactory.create(query, model);
	ResultSet resultSet = queryExecution.execSelect();
	resultSet.forEachRemaining(querySolution -> {
		stmts.add(new StatementImpl(querySolution.getResource("class"), synonym, querySolution.getLiteral("synonym")));
	});
	return stmts;
}
 
開發者ID:teamdigitale,項目名稱:ontonethub,代碼行數:20,代碼來源:IndexingJob.java

示例3: expandSubProperties

import com.hp.hpl.jena.rdf.model.Statement; //導入依賴的package包/類
private List<Statement> expandSubProperties(Model model){
	List<Statement> stmts = new ArrayList<Statement>();
	
	String sparql = "PREFIX rdfs: <" + RDFS.getURI() + ">"
			+ "SELECT DISTINCT ?property ?synonym "
			+ "WHERE { "
			+ "?property rdfs:subPropertyOf+ ?subProperty . "
			+ "?subProperty <" + synonym + "> ?synonym"
			+ "}";
	
	Query query = QueryFactory.create(sparql, Syntax.syntaxARQ);
	QueryExecution queryExecution = QueryExecutionFactory.create(query, model);
	ResultSet resultSet = queryExecution.execSelect();
	resultSet.forEachRemaining(querySolution -> {
		stmts.add(new StatementImpl(querySolution.getResource("property"), synonym, querySolution.getLiteral("synonym")));
	});
	return stmts;
}
 
開發者ID:teamdigitale,項目名稱:ontonethub,代碼行數:19,代碼來源:IndexingJob.java

示例4: getUndefinedResources

import com.hp.hpl.jena.rdf.model.Statement; //導入依賴的package包/類
public Collection<Resource> getUndefinedResources(Model model) {
	Set<Resource> result = new HashSet<Resource>();
	StmtIterator it = model.listStatements();
	while (it.hasNext()) {
		Statement stmt = it.nextStatement();
		if (stmt.getSubject().isURIResource()
				&& stmt.getSubject().getURI().startsWith(namespace)
				&& !resources.contains(stmt.getSubject())) {
			result.add(stmt.getSubject());
		}
		if (stmt.getPredicate().equals(RDF.type)) continue;
		if (stmt.getObject().isURIResource()
				&& stmt.getResource().getURI().startsWith(namespace)
				&& !resources.contains(stmt.getResource())) {
			result.add(stmt.getResource());
		}
	}
	return result;
}
 
開發者ID:d2rq,項目名稱:r2rml-kit,代碼行數:20,代碼來源:VocabularySummarizer.java

示例5: open

import com.hp.hpl.jena.rdf.model.Statement; //導入依賴的package包/類
public Object open(Assembler ignore, Resource description, Mode ignore2) {
	if (!description.hasProperty(D2RQ.mappingFile)) {
		throw new D2RQException("Error in assembler specification " + description + ": missing property d2rq:mappingFile");
	}
	if (!description.getProperty(D2RQ.mappingFile).getObject().isURIResource()) {
		throw new D2RQException("Error in assembler specification " + description + ": value of d2rq:mappingFile must be a URI");
	}
	String mappingFileURI = ((Resource) description.getProperty(D2RQ.mappingFile).getObject()).getURI();
	String resourceBaseURI = null;
	Statement stmt = description.getProperty(D2RQ.resourceBaseURI);
	if (stmt != null) {
		if (!stmt.getObject().isURIResource()) {
			throw new D2RQException("Error in assembler specification " + description + ": value of d2rq:resourceBaseURI must be a URI");
		}
		resourceBaseURI = ((Resource) stmt.getObject()).getURI();
	}
	return new ModelD2RQ(mappingFileURI, resourceBaseURI);
}
 
開發者ID:d2rq,項目名稱:r2rml-kit,代碼行數:19,代碼來源:D2RQAssembler.java

示例6: getRDFNodes

import com.hp.hpl.jena.rdf.model.Statement; //導入依賴的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

示例7: open

import com.hp.hpl.jena.rdf.model.Statement; //導入依賴的package包/類
public Object open(Assembler ignore, Resource description, Mode ignore2) {
	if (!description.hasProperty(D2RQ.mappingFile)) {
		throw new D2RQException("Error in assembler specification " + description + ": missing property d2rq:mappingFile");
	}
	if (!description.getProperty(D2RQ.mappingFile).getObject().isURIResource()) {
		throw new D2RQException("Error in assembler specification " + description + ": value of d2rq:mappingFile must be a URI");
	}
	String mappingFileURI = ((Resource) description.getProperty(D2RQ.mappingFile).getObject()).getURI();
	String resourceBaseURI = null;
	Statement stmt = description.getProperty(D2RQ.resourceBaseURI);
	if (stmt != null) {
		if (!stmt.getObject().isURIResource()) {
			throw new D2RQException("Error in assembler specification " + description + ": value of d2rq:resourceBaseURI must be a URI");
		}
		resourceBaseURI = ((Resource) stmt.getObject()).getURI();
	}
	return new ModelD2RQ(mappingFileURI, null, resourceBaseURI);
}
 
開發者ID:aitoralmeida,項目名稱:c4a_data_repository,代碼行數:19,代碼來源:D2RQAssembler.java

示例8: runQueryOnInstance

import com.hp.hpl.jena.rdf.model.Statement; //導入依賴的package包/類
/**
 * Runs a given Jena Query on a given instance and adds the inferred triples
 * to a given Model.
 * @param queryWrapper  the wrapper of the CONSTRUCT query to execute
 * @param queryModel  the query Model
 * @param newTriples  the Model to write the triples to
 * @param instance  the instance to run the inferences on
 * @param checkContains  true to only call add if a Triple wasn't there yet
 * @return true if changes were done (only meaningful if checkContains == true)
 */
public static boolean runQueryOnInstance(QueryWrapper queryWrapper, Model queryModel, Model newTriples, Resource instance, boolean checkContains) {
	boolean changed = false;
	QueryExecution qexec = ARQFactory.get().createQueryExecution(queryWrapper.getQuery(), queryModel);
	QuerySolutionMap bindings = new QuerySolutionMap();
	bindings.add(SPIN.THIS_VAR_NAME, instance);
	Map<String,RDFNode> initialBindings = queryWrapper.getTemplateBinding();
	if(initialBindings != null) {
		for(String varName : initialBindings.keySet()) {
			RDFNode value = initialBindings.get(varName);
			bindings.add(varName, value);
		}
	}
	qexec.setInitialBinding(bindings);
	Model cm = qexec.execConstruct();
	StmtIterator cit = cm.listStatements();
	while(cit.hasNext()) {
		Statement s = cit.nextStatement();
		if(!checkContains || !queryModel.contains(s)) {
			changed = true;
			newTriples.add(s);
		}
	}
	return changed;
}
 
開發者ID:BenzclyZhang,項目名稱:BimSPARQL,代碼行數:35,代碼來源:SPINInferencesWithoutConstructor.java

示例9: main

import com.hp.hpl.jena.rdf.model.Statement; //導入依賴的package包/類
public static void main(String[] args) {
	Model m = ModelFactory.createDefaultModel();
	m.read(args[0]);
	StmtIterator iter = m.listStatements();
	HashSet<String> hash = new HashSet<String>();
	while (iter.hasNext()) {
		Statement stmt = iter.next();
		RDFNode node = stmt.getObject();
		String uri = node.asResource().getURI();
		hash.add(uri);
	}
	File output = new File(args[1]);
	try {
		PrintWriter writer = new PrintWriter(output);
		for(String s : hash) {
			writer.println(s);
		}
		writer.close();
	} catch (FileNotFoundException e) {
		e.printStackTrace();
	}
}
 
開發者ID:quhfus,項目名稱:DoSeR,代碼行數:23,代碼來源:ExtractRelevantDBpediaCategories.java

示例10: getLabelsJSONObjectFromInstanceStatement

import com.hp.hpl.jena.rdf.model.Statement; //導入依賴的package包/類
static JSONObject getLabelsJSONObjectFromInstanceStatement (ArrayList<Statement> statements) throws JSONException {
    JSONObject jsonClassesObject = new JSONObject();
    ArrayList<String> coveredValues = new ArrayList<String>();
    for (int i = 0; i < statements.size(); i++) {
        Statement statement = statements.get(i);

        String predicate = statement.getPredicate().getURI();
        if (predicate.endsWith("#label")) {
            String object = "";
            if (statement.getObject().isLiteral()) {
                object = statement.getObject().asLiteral().toString();
            } else if (statement.getObject().isURIResource()) {
                object = statement.getObject().asResource().getURI();
            }
            String [] values = object.split(",");
            for (int j = 0; j < values.length; j++) {
                String value = values[j];
                if (!coveredValues.contains(value)) {
                    coveredValues.add(value);
                    jsonClassesObject.append("labels", value);
                }
            }
        }
    }
    return jsonClassesObject;
}
 
開發者ID:newsreader,項目名稱:StreamEventCoreference,代碼行數:27,代碼來源:TrigToJsonTimeLine.java

示例11: populateVersionInfo

import com.hp.hpl.jena.rdf.model.Statement; //導入依賴的package包/類
private void populateVersionInfo(final ModuleHelper helper, final Result<Module> report, final Module module, final Resource resource) {
	final Function<Statement, Optional<String>> stringFilter=new StringFilter(report);
	final List<String> versionInfos = helper.getPropertyValues(resource, owl("versionInfo"),stringFilter);
	if(!module.isVersion()) {
		if(!versionInfos.isEmpty()) {
			report.warn("Only ontology versions can have associated version info (%s)",Joiner.on(", ").join(versionInfos));
		}
	} else {
		if(versionInfos.isEmpty()) {
			report.warn("No version info defined");
		} else if(versionInfos.size()>1) {
			report.warn("Multiple version info defined (%s)",Joiner.on(", ").join(versionInfos));
		} else {
			module.withVersionInfo(versionInfos.get(0));
		}
	}
}
 
開發者ID:SmartDeveloperHub,項目名稱:sdh-vocabulary,代碼行數:18,代碼來源:Catalog.java

示例12: addRowToMODEL

import com.hp.hpl.jena.rdf.model.Statement; //導入依賴的package包/類
private void addRowToMODEL(List<Statement> sa, String key, String puri) {
	for (Statement s : sa) {
		if (MODEL.contains(s)) {
			continue;
		}
		// add to existing resource with same key if exists
		if (s.getPredicate().getLocalName().equals(key)) {
			ResIterator it	=	MODEL.listResourcesWithProperty(s.getPredicate(), s.getObject());
			if (it.hasNext()) { // assume all members are equal
				Resource rsc	= it.nextResource(); // get parent
				Property p	= ResourceFactory.createProperty(genOURI(), puri);
				Statement st	= ResourceFactory.createStatement(rsc, p, s.getSubject());

				MODEL.add(st);

				continue;
			}
		}

		MODEL.add(s);
	}
}
 
開發者ID:wxwilcke,項目名稱:mdb2rdf,代碼行數:23,代碼來源:RdbToRdf.java

示例13: fetchLabels

import com.hp.hpl.jena.rdf.model.Statement; //導入依賴的package包/類
private void fetchLabels(Model m)
{
    Map<String,String> map = new HashMap();
    Property           p   = m.getProperty(SKOS_PREF_LABEL);

    ResIterator rIter = m.listResourcesWithProperty(m.getProperty(RDF_TYPE));
    while ( rIter.hasNext() )
    {
        Resource r = rIter.next();
        fetchAlternatives(map, r);

        StmtIterator sIter = r.listProperties(p);
        while ( sIter.hasNext() )
        {
            Statement stmt = sIter.next();
            put(stmt.getSubject(), getKey(stmt.getString(), map));
        }

        map.clear();
    }
}
 
開發者ID:hugomanguinhas,項目名稱:europeana,代碼行數:22,代碼來源:AmbiguityFetch.java

示例14: writeStatement

import com.hp.hpl.jena.rdf.model.Statement; //導入依賴的package包/類
private void writeStatement(Statement stmt, PrintStream out)
{
    String             name  = getQName(stmt.getPredicate());
    Map<String,String> attrs = null;
    String             value = null;
    RDFNode node = stmt.getObject();
    if ( node.isLiteral() )
    {
        Literal l = node.asLiteral();
        value = l.getString();

        String lang = l.getLanguage();
        if ( !lang.isEmpty()  ) { attrs = Collections.singletonMap("xml:lang", lang); }

        String datatype = l.getDatatypeURI();
        if ( datatype != null ) { attrs = Collections.singletonMap("rdf:datatype", datatype); }
    }
    else {
        attrs = Collections.singletonMap("rdf:resource", getURI(node.asResource()));
    }
    writeProperty(name, attrs, value, out);
}
 
開發者ID:hugomanguinhas,項目名稱:europeana,代碼行數:23,代碼來源:EDMXMLWriter.java

示例15: copyAllowedProperties

import com.hp.hpl.jena.rdf.model.Statement; //導入依賴的package包/類
protected void copyAllowedProperties(Model readModel, Model model, Set<Resource> classes,
        Set<Property> allowedProperties) {
    StmtIterator stmtIterator = readModel.listStatements();
    Statement s;
    Literal label;
    while (stmtIterator.hasNext()) {
        s = stmtIterator.next();
        if (classes.contains(s.getSubject()) && allowedProperties.contains(s.getPredicate())
                && (!s.getObject().isAnon())) {
            if (s.getPredicate().equals(RDFS.label)) {
                label = s.getObject().asLiteral();
                if (label.getLanguage().equals("en")) {
                    model.add(s.getSubject(), RDFS.label,
                            model.createLiteral(label.getString().toLowerCase(), "en"));
                }
            } else {
                model.add(s);
            }
        }
    }
}
 
開發者ID:dice-group,項目名稱:Cetus,代碼行數:22,代碼來源:DolceClassHierarchyLoader.java


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