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
| import java.io.BufferedReader;
import java.io.FileReader;
import org.neo4j.cypher.ExecutionEngine;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.ResourceIterable;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
public class FR {
private static final String DB_Path="C:\\Users/hiba/Downloads/neo4j-community-2.0.1-windows/neo4j-community-2.0.1/data";
String myString;
static GraphDatabaseService Graph2;
static Node ClientIpp;
static Node PageVisitée;
static Relationship myRelationshipp;
void createDb()
{
Graph2 = new GraphDatabaseFactory().newEmbeddedDatabase(DB_Path);
}
private static enum RelTypes implements RelationshipType
{
regarde
}
public static void main(String[] args) throws Exception {
FR blabla=new FR();
blabla.createDb();
FileReader file= new FileReader("c:/exemple.txt");
BufferedReader reader= new BufferedReader(file);
String ligne;
String myString ;
String[] splitArray=null;
boolean existe=false;
int lignenumber=0;
while ((ligne = reader.readLine()) != null )
{
splitArray=ligne.split("[;:///]");
for(int i = 0; i< splitArray.length;i++){
// On affiche chaque élément du tableau
System.out.println("élement n° " + i + "=[" + splitArray[i]+"]");
}
Transaction tx = Graph2.beginTx();
try
{
ResourceIterable <Node> result;
Label client = null; //initialisation
String name = null; //initialisation
result = Graph2.findNodesByLabelAndProperty(client, name, splitArray[2]); //spliArray[2] c'est le champs @Ipp
if (result != null)
{
// ici c'est à dire que le noeud avec ces conditions existe donc je dois retourner le noeud en question
//mais result est de type iterator qui contient tous les noeuds qui vérifient ces conditions
//et je peux pas faire ceci PageVisitée = result
}
else
{ ClientIpp = Graph2.createNode();
ClientIpp.setProperty( "name", splitArray[2]);
ClientIpp.addLabel(client);
}
Label page = null;
result = Graph2.findNodesByLabelAndProperty(page, name, splitArray[11]); //spliArray[11] c'est le champs Page visité par l'@Ipp
if (result != null)
{
// ici c'est à dire que le noeud avec ces conditions existe donc je dois retourner le noeud en question
//mais result est de type iterator qui contient tous les noeuds qui vérifient ces conditions
//et je peux pas faire ceci PageVisitée = result
}
else // le noeud n'existe pas je dois le créer
{
PageVisitée = Graph2.createNode();
PageVisitée.addLabel(page);
PageVisitée.setProperty( "name", splitArray[11]);
}
myRelationshipp = ClientIpp.createRelationshipTo( PageVisitée, RelTypes.regarde);
myRelationshipp.setProperty( "relationship-type", "regarde");
myString = (ClientIpp.getProperty("name").toString())+" "+( myRelationshipp.getProperty("relationship-type").toString()) + " "+ (PageVisitée.getProperty( "name").toString() );
System.out.println(myString);
tx.success();
}
finally
{
tx.finish();
}
lignenumber++;
}
reader.close();
}
} |
Partager