/[fenfire]/fenfire/org/fenfire/swamp/Graphs.java
ViewVC logotype

Diff of /fenfire/org/fenfire/swamp/Graphs.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by mudyc, Wed May 28 13:45:50 2003 UTC revision 1.7 by mudyc, Wed May 28 16:20:22 2003 UTC
# Line 29  package org.fenfire.swamp; Line 29  package org.fenfire.swamp;
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);
# Line 72  public class Graphs { Line 79  public class Graphs {
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();
# Line 92  public class Graphs { Line 100  public class Graphs {
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  }  }

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26