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
|
import java.io.File;
import static neo4j.Neo4j.graphDb;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.neo4j.graphdb.index.Index;
import org.neo4j.kernel.GraphDatabaseAPI;
//import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.neo4j.server.WrappingNeoServerBootstrapper;
import twitter4j.HashtagEntity;
import twitter4j.MediaEntity;
import twitter4j.Status;
import twitter4j.URLEntity;
import twitter4j.UserMentionEntity;
/**
*
* @author kami
*/
public class Twitter {
private static enum RelType implements RelationshipType
{
MENTION,
TWITT,
HASHTAG,
URL,
MEDIA,
RT
}
private static String DB_PATH = "C:\\neo4j-community-3.1.3\\data\\databases\\graph.db";
private Index _entitiesIndex ;
private Index _UserIndex ;
private Index _TwittIndex ;
private Index _URLIndex ;
private Index _HashtagIndex ;
private Index _MediaIndex ;
private Index _relMENTION;
private Index _relTWITT;
private Index _relHASHTAG;
private Index _relURL;
private Index _relMEDIA;
private Index _relRT;
static GraphDatabaseService graphDB;
static int _relcounter = 0;
public Twitter()
{
graphDB = new GraphDatabaseFactory().newEmbeddedDatabase(new File(DB_PATH));
System.out.println("acces a la base "+graphDB);
createDB();
}
private void createDB()
{
Transaction tx = graphDB.beginTx();
try
{
_entitiesIndex= graphDB.index().forNodes( "twitterEntities" );
System.out.println("entity index entities ajout");
_UserIndex= graphDB.index().forNodes( "User" );
System.out.println("user index entities ajout");
_TwittIndex= graphDB.index().forNodes( "Twitt" );
_URLIndex = graphDB.index().forNodes( "URL" );
_HashtagIndex= graphDB.index().forNodes( "Hashtag" );
_MediaIndex= graphDB.index().forNodes( "Media" );
_relMENTION = graphDB.index().forRelationships("Mention");
_relTWITT = graphDB.index().forRelationships("Twitt");
_relHASHTAG = graphDB.index().forRelationships("Hashtag");
_relURL = graphDB.index().forRelationships("URL");
_relMEDIA = graphDB.index().forRelationships("Media");
_relRT = graphDB.index().forRelationships("RT");
tx.success();
}
catch(Exception e)
{
e.printStackTrace();
}
//graphDB=new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(new File(DB_PATH)).newGraphDatabase();
WrappingNeoServerBootstrapper srv = new WrappingNeoServerBootstrapper((GraphDatabaseAPI) graphDB);
srv.start();
} |
Partager