本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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();
}
}
示例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;
}
示例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));
}
}
}
示例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);
}
}
示例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();
}
}
示例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);
}
示例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);
}
}
}
}