15 |
|
|
16 |
/** Create a new resource with given type. |
/** Create a new resource with given type. |
17 |
*/ |
*/ |
18 |
static public Object N(Fen fen, Object type) { |
static public Object N(Graph graph, Object type) { |
19 |
Object obj = Nodes.N(); |
Object obj = Nodes.N(); |
20 |
fen.graph.add(obj, RDF.type, type); |
graph.add(obj, RDF.type, type); |
21 |
|
|
22 |
if(dbg) { |
if(dbg) { |
23 |
p("N: "+fen+" "+fen.graph+" "+fen.constgraph+ |
p("N: "+graph+" "+obj+" "+type); |
24 |
" "+obj+" "+type); |
if (!isNodeType(graph, obj, type)) throw new Error("Impossible!"); |
|
if (!isNodeType(fen, obj, type)) throw new Error("Impossible!"); |
|
25 |
} |
} |
26 |
|
|
27 |
return obj; |
return obj; |
30 |
|
|
31 |
/** Check if node is the type which is asked. |
/** Check if node is the type which is asked. |
32 |
*/ |
*/ |
33 |
static public boolean isNodeType(Fen fen, Object node, Object type) { |
static public boolean isNodeType(Graph graph, Object node, Object type) { |
34 |
if(dbg) p("Isnodetype: "+node+" "+type); |
if(dbg) p("Isnodetype: "+node+" "+type); |
35 |
Iterator it = fen.constgraph.findN_11X_Iter(node, RDF.type); |
Iterator it = graph.findN_11X_Iter(node, RDF.type); |
36 |
while(it.hasNext()) { |
while(it.hasNext()) { |
37 |
Object obj = it.next(); |
Object obj = it.next(); |
38 |
if(dbg) p(" entry: "+ obj); |
if(dbg) p(" entry: "+ obj); |
44 |
|
|
45 |
/** Get int attribute (from a literal). |
/** Get int attribute (from a literal). |
46 |
*/ |
*/ |
47 |
static public int getInt(Fen fen, Object node, Object pre) { |
static public int getInt(Graph graph, Object node, Object pre) { |
48 |
Literal lit = (Literal)fen.constgraph.find1_11X(node, pre); |
Literal lit = (Literal)graph.find1_11X(node, pre); |
49 |
return Integer.parseInt(lit.getTextString() ); |
return Integer.parseInt(lit.getTextString() ); |
50 |
} |
} |
51 |
|
|
52 |
/** Set int attribute (literal). |
/** Set int attribute (literal). |
53 |
*/ |
*/ |
54 |
static public void setInt(Fen fen, Object node, Object pre, int val) { |
static public void setInt(Graph graph, Object node, Object pre, int val) { |
55 |
fen.graph.set1_11X(node, pre, |
graph.set1_11X(node, pre, |
56 |
Nodes.getStringLiteral( |
Nodes.getStringLiteral( |
57 |
Integer.toString(val))); |
Integer.toString(val))); |
58 |
} |
} |