29 |
import org.fenfire.swamp.impl.*; |
import org.fenfire.swamp.impl.*; |
30 |
import com.hp.hpl.mesa.rdf.jena.model.*; |
import com.hp.hpl.mesa.rdf.jena.model.*; |
31 |
import com.hp.hpl.mesa.rdf.jena.mem.*; |
import com.hp.hpl.mesa.rdf.jena.mem.*; |
32 |
|
import com.hp.hpl.mesa.rdf.jena.common.*; |
33 |
import java.util.Iterator; |
import java.util.Iterator; |
34 |
|
|
35 |
public class Graphs { |
public class Graphs { |
36 |
public static boolean dbg = true; |
public static boolean dbg = false; |
37 |
public static void p(String s) { System.out.println("swamp.Graphs:: "+s); } |
public static void p(String s) { System.out.println("swamp.Graphs:: "+s); } |
38 |
|
|
39 |
|
final private static String urn5 = //"urn5"; |
40 |
|
"http://www.iana.org/assignments/urn-informal/urn-5"; |
41 |
|
|
42 |
public static Model toModel(ConstGraph g) { |
public static Model toModel(ConstGraph g) { |
43 |
try { |
try { |
44 |
Model m = new ModelMem(); |
Model m = new ModelMem(); |
45 |
for (Iterator i=g.findN_XAA_Iter(); i.hasNext();) { |
for (Iterator i=g.findN_XAA_Iter(); i.hasNext();) { |
46 |
Object o = i.next(); |
Object o = i.next(); |
47 |
Resource sub = m.createResource(Nodes.toString(o)); |
//Resource sub = m.createResource("", Nodes.toString(o)); |
48 |
|
Resource sub = new ResourceImpl(urn5, Nodes.toString(o), m); |
49 |
|
|
50 |
for (Iterator j=g.findN_1XA_Iter(o); j.hasNext();) { |
for (Iterator j=g.findN_1XA_Iter(o); j.hasNext();) { |
51 |
Object p = j.next(); |
Object p = j.next(); |
52 |
Property prop = m.createProperty("", Nodes.toString(p)); |
Property prop = m.createProperty(urn5, Nodes.toString(p)); |
53 |
|
|
54 |
for (Iterator k=g.findN_11X_Iter(o,p); k.hasNext();) { |
for (Iterator k=g.findN_11X_Iter(o,p); k.hasNext();) { |
55 |
Object q = k.next(); |
Object q = k.next(); |
56 |
if(q instanceof Literal) { |
if(q instanceof Literal) { |
57 |
p("Literal! : "+ q); |
if (dbg) p("Literal! : "+ q); |
58 |
String s = ((Literal)q).getTextString(); |
String s = ((Literal)q).getTextString(); |
59 |
sub.addProperty(prop, s); |
sub.addProperty(prop, s); |
60 |
} else { |
} else { |
61 |
p("Resource! : "+ q); |
if (dbg) p("Resource! : "+ q); |
62 |
Resource ob = m.createResource(Nodes.toString(q)); |
//Resource ob = m.createResource("", Nodes.toString(q)); |
63 |
sub.addProperty(prop, o); |
Resource ob = new ResourceImpl(urn5, Nodes.toString(q), m); |
64 |
|
sub.addProperty(prop, ob); |
65 |
} |
} |
66 |
} |
} |
67 |
} |
} |
68 |
} |
} |
69 |
|
if (dbg) m.write(new java.io.PrintWriter(System.out)); |
70 |
return m; |
return m; |
71 |
} catch(Exception e) { |
} catch(Exception e) { |
72 |
throw new Error("Exception converting graph "+e); |
throw new Error("Exception converting graph "+e); |
79 |
p("toGraph!"); |
p("toGraph!"); |
80 |
StmtIterator j=m.listStatements(); |
StmtIterator j=m.listStatements(); |
81 |
while(j.hasNext()) { |
while(j.hasNext()) { |
82 |
p("And there are: "+ |
p("And there are: "); |
83 |
((Statement)j.next()).getString() ); |
p(" "+ j.next() ); |
84 |
} |
} |
85 |
|
p("ok?!"); |
86 |
} |
} |
87 |
|
|
88 |
Graph g = new HashGraph(); |
Graph g = new HashGraph(); |
100 |
} |
} |
101 |
return g; |
return g; |
102 |
} catch(Exception e) { |
} catch(Exception e) { |
103 |
throw new Error("Exception converting graph"); |
throw new Error("Exception converting graph" + e); |
104 |
} |
} |
105 |
} |
} |
106 |
} |
} |