25 |
throw new Error("ShortRDF has RDFException!"); |
throw new Error("ShortRDF has RDFException!"); |
26 |
}} |
}} |
27 |
|
|
28 |
|
public static Resource getSubj(Model model, RDFNode obj, Property predicate) |
29 |
|
{ try { |
30 |
|
Selector selector = new SelectorImpl(null, predicate, obj); |
31 |
|
StmtIterator iter = model.listStatements(selector); |
32 |
|
if (iter.hasNext()) { |
33 |
|
Statement stmt = iter.next(); |
34 |
|
return (Resource)stmt.getSubject(); |
35 |
|
} |
36 |
|
else throw new Error("No available resources!"); |
37 |
|
} catch (RDFException e) { |
38 |
|
pa("Exception ocurred!: "+e); |
39 |
|
throw new Error("ShortRDF has RDFException!"); |
40 |
|
}} |
41 |
|
|
42 |
|
|
43 |
public static int getInt(Model model, RDFNode node, Property predicate) |
public static int getInt(Model model, RDFNode node, Property predicate) |
44 |
{ try { |
{ try { |
45 |
Selector selector = new SelectorImpl((Resource)node, predicate, (RDFNode) null); |
Selector selector = new SelectorImpl((Resource)node, predicate, (RDFNode) null); |
75 |
*/ |
*/ |
76 |
public static boolean isNodeType(Model model, RDFNode node, RDFNode type) |
public static boolean isNodeType(Model model, RDFNode node, RDFNode type) |
77 |
{ try { |
{ try { |
78 |
|
Selector selector = new SelectorImpl((Resource)node, RDF.type, type); |
79 |
|
StmtIterator iter = model.listStatements(selector); |
80 |
|
while (iter.hasNext()) { |
81 |
|
Statement stmt = iter.next(); |
82 |
|
if (stmt.getSubject().equals((Resource)node)) |
83 |
|
return true; |
84 |
|
} |
85 |
|
/* |
86 |
if ( ((Resource)node).getProperty(RDF.type).getObject().equals((Resource)type)) |
if ( ((Resource)node).getProperty(RDF.type).getObject().equals((Resource)type)) |
87 |
return true; |
return true; |
88 |
else |
else |
89 |
return false; |
*/ |
90 |
|
return false; |
91 |
} catch (RDFException e) { |
} catch (RDFException e) { |
92 |
pa("Exception ocurred!: "+e); |
pa("Exception ocurred!: "+e); |
93 |
throw new Error("ShortRDF has RDFException!"); |
throw new Error("ShortRDF has RDFException!"); |
97 |
static public RDFNode newNode(Model model) { |
static public RDFNode newNode(Model model) { |
98 |
return newNode(model, null); |
return newNode(model, null); |
99 |
} |
} |
100 |
static public RDFNode newNode(Model model, RDFNode object) |
static public RDFNode newNode(Model model, RDFNode type) |
101 |
{ try { |
{ try { |
102 |
String uri = URN5Namespace.instance.generateId(); |
String uri = URN5Namespace.instance.generateId(); |
103 |
if (object == null) { |
if (type == null) { |
104 |
return model.createResource(uri); |
return model.createResource(uri); |
105 |
} else { |
} else { |
106 |
Resource res = model.createResource(uri); |
Resource res = model.createResource(uri); |
107 |
res.addProperty(RDF.type, (Resource)object); |
res.addProperty(RDF.type, (Resource)type); |
108 |
return res; |
return res; |
109 |
} |
} |
110 |
} catch (RDFException e) { |
} catch (RDFException e) { |
136 |
|
|
137 |
((Resource)node).addProperty(property, res); |
((Resource)node).addProperty(property, res); |
138 |
res.addProperty(RDF.type, (Resource)type); |
res.addProperty(RDF.type, (Resource)type); |
|
|
|
|
pa("node: "+ res); |
|
|
pa("foo: " + res.getProperty(RDF.type)); |
|
|
if ( ((Resource)res).getProperty(RDF.type).equals((Resource)type)) |
|
|
pa("ALL RIGHT!"); |
|
|
if(!isNodeType(model, res, type)) throw new Error("ARGH"); |
|
|
|
|
139 |
return res; |
return res; |
140 |
|
|
141 |
} catch (RDFException e) { |
} catch (RDFException e) { |