1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package graph.classes;
/**
*
* @author Essia
*/
import java.util.*;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.util.FileManager;
import java.io.*;
import java.net.URI;
public class O_graph {
private URI path; /* fichier de l'ontologie*/
private Vector <NODE>nodes;
private Vector <LINK>links;
public O_graph(URI path) /*constructeur nacessite URI*/
{
this.path=path;
nodes=new Vector<NODE>();
links=new Vector<LINK>();
}
public Model connect() /*connection au ontologie dans le fichier */
{
Model model = ModelFactory.createDefaultModel();
InputStream in = FileManager.get().open( this.path.toString() );
if (in == null) {
throw new IllegalArgumentException( "File: " + this.path + " not found");
}
// read the RDF/XML file
model.read(in, "");
return model; /* return model qui sera utilisée pour le parcour
des données de l'ontologie*/
}
public Vector getLinks()
{
return links;
}
public Vector getNodes()
{
return nodes;
}
public void setPath(URI path)
{
this.path=path;
}
public URI getPath()
{
return this.path;
}
public boolean contain(String s1,Vector v)
{
for(int i=0;i<v.size();i++){
NODE m=(NODE) v.elementAt(i);
if(m.getName().equals(s1))
return true;
}
return false;
}
public void addNode(String name,String type)
{
nodes.add(new NODE(name,type));
}
public void viewNodes()
{
System.out.println(" ****************NODES**************\n\n");
Iterator it=nodes.iterator();
while(it.hasNext())
{
NODE node=(NODE) it.next();
System.out.println(node.getName()+"------>"+node.getType());
}
}
public NODE findNode(String name)
{
Iterator it=nodes.iterator();
while(it.hasNext())
{
NODE node=(NODE)it.next();
if(node.getName().equals(name))
return node;
}
return null;
}
public void addLink(String type,NODE node1,NODE node2)
{
links.add(new LINK(type,node1,node2));
}
public void viewLinks()
{
System.out.println("\n\n ****************LINKS**************\n\n");
Iterator it=links.iterator();
while(it.hasNext())
{
LINK link=(LINK)it.next();
System.out.println(link.getSource().getName()+"---->"+link.getType()+"---->"+link.getTraget().getName());
}
}
public Vector getRelatedLink(NODE node) /*return les liens relatives a node*/
{
Vector <LINK>v=new Vector<LINK>();
for(int i=0;i<links.size();i++)
{
LINK link1=(LINK) links.elementAt(i);
if(link1.getSource().equals(node)||link1.getTraget().equals(node))
v.add(link1);
}
if(v.size()==0) return null;
return v;
}
public Vector getRelatedLinkbyType(String type,NODE node)/*return les noeuds relatives a node par type*/
{
Vector <LINK>v=new Vector<LINK>();
for(int i=0;i<links.size();i++)
{
LINK link1=(LINK) links.elementAt(i);
if((link1.getSource().equals(node)||link1.getTraget().equals(node))&&link1.getType().equals(type))
v.add(link1);
}
if(v.size()==0) return null;
return v;
}
public Vector getRelatednode(NODE n)/*return les noeuds relatives a node*/
{
Vector <NODE>v=new Vector<NODE>();
for(int i=0;i<links.size();i++)
{
LINK link1=(LINK) links.elementAt(i);
if(link1.getSource().equals(n)&&!link1.getType().equals("comment")&&!link1.getType().equals("label"))
v.add(link1.getTraget());
else if(link1.getTraget().equals(n)&&!link1.getType().equals("comment")&&!link1.getType().equals("label"))
v.add(link1.getSource());
}
if(v.size()==0) return null;
return v;
}
} |