本文整理汇总了Java中org.apache.jena.rdf.model.Statement.getPredicate方法的典型用法代码示例。如果您正苦于以下问题:Java Statement.getPredicate方法的具体用法?Java Statement.getPredicate怎么用?Java Statement.getPredicate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.rdf.model.Statement
的用法示例。
在下文中一共展示了Statement.getPredicate方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mergeDescription
import org.apache.jena.rdf.model.Statement; //导入方法依赖的package包/类
private void mergeDescription(Resource ir, Resource r, boolean flagOK, Map<RDFNode,RDFNode> visited) {
for (StmtIterator si = r.listProperties(); si.hasNext(); ) {
Statement stmt = si.nextStatement();
Property p = stmt.getPredicate();
RDFNode o = stmt.getObject();
if (flagOK && r.hasProperty(RDF.type, OWL.Class))
ir.addProperty(RDF.type, infModel.getResource(Gloze.OK));
if (o.isLiteral())
ir.addProperty(p,o);
else if (!o.isAnon())
ir.addProperty(p,infModel.createResource(((Resource)o).getURI()));
else if (o.isAnon() && visited.containsKey(o))
ir.addProperty(p,visited.get(o));
else { // recursively merge anonymous objects
Resource a = infModel.createResource();
visited.put(o,a);
ir.addProperty(p,a);
mergeDescription(a, (Resource)o, false, visited);
}
}
}
示例2: noSchemaToXML
import org.apache.jena.rdf.model.Statement; //导入方法依赖的package包/类
public static boolean noSchemaToXML(Document doc, RDFNode rdf, Context ctx) {
boolean qualify = ctx.getDefaultNS()!=null;
if (rdf instanceof Resource) {
Resource r = (Resource) rdf;
for (StmtIterator i = r.listProperties(); i.hasNext(); ) {
Statement stmt = i.nextStatement();
Property p = stmt.getPredicate();
// ignore RDF properties eg. RDF:type
// take the first (non-rdf) property we find as document element
if (!p.getURI().startsWith(RDF.getURI())) {
Element e = noSchemaToElement(doc,p,ctx);
doc.appendChild(e);
noSchemaToXML(e,stmt.getObject(),qualify,ctx);
return true;
}
}
}
return false;
}
示例3: getModelKeyWords
import org.apache.jena.rdf.model.Statement; //导入方法依赖的package包/类
/**
* Extracts the key words from the model's statements.
* This includes the Literals and the localNames of Resources and Predicates.
*
* @param model Model to extract key words
* @return List of key word strings
*/
public List<String> getModelKeyWords(Model model) {
List<String> keyWords = new ArrayList<String>();
StmtIterator statementIter = model.listStatements();
Statement s;
Property predicate;
RDFNode object;
while (statementIter.hasNext()) {
s = statementIter.nextStatement();
predicate = s.getPredicate();
object = s.getObject();
keyWords.add(predicate.getLocalName());
// local name of (non blank nodes) Resources
if (object instanceof Resource && object.toString().contains("/")) {
keyWords.add(object.asResource().getLocalName());
} else if (object instanceof Literal) {
// object is a Literal
keyWords.add(object.toString());
}
}
return keyWords;
}
示例4: createIndividual
import org.apache.jena.rdf.model.Statement; //导入方法依赖的package包/类
private Model createIndividual(VirtualEntity virtualEntity) {
// some definitions
String personURI = "http://somewhere/JohnSmith";
String givenName = "John";
String familyName = "Smith";
String fullName = givenName + " " + familyName;
// create an empty Model
Model model = ModelFactory.createDefaultModel();
// create the resource
// and add the properties cascading style
Resource johnSmith
= model.createResource(personURI)
.addProperty(VCARD.FN, fullName)
.addProperty(VCARD.N,
model.createResource()
.addProperty(VCARD.Given, givenName)
.addProperty(VCARD.Family, familyName));
// list the statements in the Model
StmtIterator iter = model.listStatements();
// print out the predicate, subject and object of each statement
while (iter.hasNext()) {
Statement stmt = iter.nextStatement(); // get next statement
Resource subject = stmt.getSubject(); // get the subject
Property predicate = stmt.getPredicate(); // get the predicate
RDFNode object = stmt.getObject(); // get the object
System.out.print(subject.toString());
System.out.print(" " + predicate.toString() + " ");
if (object instanceof Resource) {
System.out.print(object.toString());
} else {
// object is a literal
System.out.print(" \"" + object.toString() + "\"");
}
System.out.println(" .");
}
return model;
}
示例5: toXML
import org.apache.jena.rdf.model.Statement; //导入方法依赖的package包/类
public boolean toXML(Document doc, Resource rez) throws Exception {
StmtIterator i = rez.listProperties();
while (i.hasNext()) {
Statement s = i.nextStatement();
Property p = s.getPredicate();
element e = getElement(p.getURI());
if (e!=null && e.toXML(doc, s.getObject(),this)) return true;
}
return false;
}
示例6: processModel
import org.apache.jena.rdf.model.Statement; //导入方法依赖的package包/类
public ColouredGraph processModel(Model model) {
ColourPalette vertexPalette = createVertexPalette(model);
ColourPalette edgePalette = createEdgePalette(model);
ColouredGraph graph = new ColouredGraph(vertexPalette, edgePalette);
ObjectIntOpenHashMap<Resource> resourceIdMapping = new ObjectIntOpenHashMap<Resource>();
StmtIterator iterator = model.listStatements();
Statement statement;
Resource subject, object;
Property property;
int subjectId, propertyId, objectId;
String propertyUri;
// Iterator over all statements
while (iterator.hasNext()) {
statement = iterator.next();
subject = statement.getSubject();
// Add the subject if it is not existing
if (resourceIdMapping.containsKey(subject)) {
subjectId = resourceIdMapping.get(subject);
} else {
subjectId = graph.addVertex();
resourceIdMapping.put(subject, subjectId);
}
// if this statement has a resource as object
if (statement.getObject().isResource()) {
// Add the object if it is not existing
object = statement.getObject().asResource();
if (resourceIdMapping.containsKey(object)) {
objectId = resourceIdMapping.get(object);
} else {
objectId = graph.addVertex();
resourceIdMapping.put(object, objectId);
}
// Add the property if it is not existing
property = statement.getPredicate();
propertyId = graph.addEdge(subjectId, objectId);
// Set the colour of the edge
propertyUri = property.getURI();
if (!edgePalette.containsUri(propertyUri)) {
edgePalette.addColour(propertyUri);
}
graph.setEdgeColour(propertyId, edgePalette.getColour(propertyUri));
// if this triple defines the class of the subject
if (property.equals(RDF.type)) {
graph.setVertexColour(subjectId,
vertexPalette.addToColour(graph.getVertexColour(subjectId), object.getURI()));
}
}
}
return graph;
}
示例7: toXML
import org.apache.jena.rdf.model.Statement; //导入方法依赖的package包/类
public void toXML(Element e, Resource subject, Set<Statement> pending, Context ctx) {
String uri = createURI(ctx.getModel(),ctx);
try {
// the attribute may be defined locally or globally by ref
attribute def = getDefinition(ctx.getModel(),ctx);
if (!ctx.isFixed() && getFixed()!=null) return;
String type = def!=null?expandQName(ctx.getDefaultNS(),def.getType(),ctx.getModel()):null;
if (type==null && simpleType==null) type = schema.XSD_URI+"#anySimpleType";
if (ref!=null && ref.equals("xml:lang")) {
String l = subject.getProperty(RDF.value).getLiteral().getLanguage();
if (l!=null && !l.equals("")) e.setAttribute("xml:lang", l);
}
if (ref!=null && ref.equals("xml:id")) {
if (!subject.isAnon())
e.setAttribute("xml:id", subject.getLocalName());
}
else if (type!=null && type.startsWith(schema.XSD_URI)) {
if (type.endsWith("#ID")) {
if (!subject.isAnon() && !getUse().equals("prohibited")) {
// derive attribute from resource URI
e.setAttribute(def.getName(), new URI(subject.getURI()).getFragment());
}
else if (getUse().equals("required"))
Gloze.logger.warn("missing required ID "+getName());
return;
}
}
// look for attributes that correspond to RDF properties
Set<Statement> done = new HashSet<Statement>();
for (Statement stmt: pending) {
Property p = stmt.getPredicate();
if (uri.equals(p.getURI())) { // && !done.contains(s)) {
toXML(e, ctx, def, type, stmt.getObject());
done.add(stmt);
}
}
pending.removeAll(done);
} catch (Exception x) {}
}
示例8: toXML
import org.apache.jena.rdf.model.Statement; //导入方法依赖的package包/类
public void toXML(Element e, Resource subject, Set<Statement> pending, Context ctx) {
Document doc = e.getOwnerDocument();
schema xs = (schema) this.get_owner();
Set<Statement> done = new HashSet<Statement>();
boolean qualify = !(namespace.equals("##local") && xs.getTargetNamespace()==null);
for (Statement s: pending) {
Property p = s.getPredicate();
// ignore e.g. iterated statements
if (p.getURI().startsWith(RDF.getURI())) continue;
// find an attribute that corresponds to this property
attribute a = ctx.getAttribute(p.getURI());
if (a!=null) a.toXML(e,s.getObject(),ctx);
else if (!getProcessContents().equals("strict")) {
// construct a new attibute for the property
String ns = p.getNameSpace(), nsAlt=null;
if (ns.charAt(ns.length()-1)=='#') nsAlt = ns.substring(0,ns.length()-1);
String pref = ctx.getModel().getNsURIPrefix(nsAlt);
if (pref!=null) ns = nsAlt;
else pref = ctx.getModel().getNsURIPrefix(ns);
// check this new property is permitted by the namespace constraint
if (namespace.contains("##any") ||
(namespace.contains("##other") && !ns.equals(xs.getTargetNamespace())) ||
(namespace.contains("##local") ||
namespace.contains(ns) || namespace.contains(nsAlt))) {
Attr attr;
if (qualify && !(ns.equals(ctx.getDefaultNS()) || ctx.getDefaultNS().equals(nsAlt))) {
attr = doc.createAttributeNS(ns, p.getLocalName());
attr.setPrefix(pref);
}
else attr = doc.createAttribute(p.getLocalName());
attr.setNodeValue(s.getString());
if (qualify) e.setAttributeNodeNS(attr);
else e.setAttributeNode(attr);
}
done.add(s);
}
}
pending.removeAll(done);
if (!subject.isAnon() && namespace.contains(XML) && !getProcessContents().equals("strict")) {
e.setAttributeNS(XML,"id",subject.getLocalName());
}
else if (subject.hasProperty(RDF.value) && namespace.contains(XML) && !getProcessContents().equals("strict")) {
// if there are multiple values we assume they are all the same language
String lang = subject.getProperty(RDF.value).getLanguage();
if (lang!=null) e.setAttributeNS(XML,"lang",lang);
}
}
示例9: main
import org.apache.jena.rdf.model.Statement; //导入方法依赖的package包/类
public static void main(String[] args) {
Model model = FileManager.get().loadModel("out/eswc_data_final.rdf");
StmtIterator stmtIterator = model.listStatements(null,
model.createProperty("http://dpedia.org/ontology/thumbnail"),
(RDFNode) null);
Model modelTmp = ModelFactory.createDefaultModel();
while (stmtIterator.hasNext()) {
Statement stmt = stmtIterator.next();
Resource subject = stmt.getSubject();
Property predicate = stmt.getPredicate();
RDFNode object = stmt.getObject();
String paperId = subject.getURI().substring(
subject.getURI().lastIndexOf("/") + 1);
String name = object.toString().replace(
"http://wit.istc.cnr.it/eswc-stc/images/papers/resized/",
"");
String track = name.substring(0, name.lastIndexOf("/"));
File file;
if (!name.endsWith(".jpg"))
file = new File("img/papers/" + name + ".jpg");
else
file = new File("img/papers/" + name);
file.renameTo(new File("img/papers/" + track + "/" + paperId
+ ".jpg"));
Resource newImg = modelTmp
.createResource("http://wit.istc.cnr.it/eswc-stc/images/papers/resized/"
+ track + "/" + paperId + ".jpg");
model.add(subject, predicate, newImg);
}
model.removeAll(null,
model.createProperty("http://dpedia.org/ontology/thumbnail"),
(RDFNode) null);
model.add(modelTmp);
}