version1.Neo4jTest.Wiki2Neo4j.java Source code

Java tutorial

Introduction

Here is the source code for version1.Neo4jTest.Wiki2Neo4j.java

Source

package version1.Neo4jTest;

/**
 * Licensed to Neo Technology under one or more contributor
 * license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright
 * ownership. Neo Technology licenses this file to you under
 * the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import java.awt.Label;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.TreeMap;
import java.util.Vector;
import javassist.bytecode.Descriptor.Iterator;
import org.json.JSONException;
import org.json.JSONObject;
//import org.neo4j.cypher.internal.compiler.v2_1.planDescription.PlanDescription.Arguments$;
import org.neo4j.graphdb.Direction;
import org.neo4j.graphdb.DynamicLabel;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
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.graphdb.index.IndexHits;
import org.neo4j.graphdb.index.IndexManager;
import org.neo4j.graphdb.index.RelationshipIndex;
import org.neo4j.graphdb.schema.IndexDefinition;
import org.neo4j.graphdb.schema.Schema;
import org.neo4j.kernel.EmbeddedGraphDatabase;

import WikiLinks.WikiLinks;
import subsets.Cube;
import subsets.GenerateSCSubset;

public class Wiki2Neo4j {
    private static final String DB_PATH = "C://Users//frisch//Desktop//Neo4j//test88";

    public String greeting;

    // START SNIPPET: vars
    GraphDatabaseService graphDb;
    Node firstNode;
    Node secondNode;
    Node thirdNode;
    String version = "Version 1.2";
    TreeMap<String, Node> string_node = new TreeMap();
    TreeMap<String, Node> cube_properties = new TreeMap();
    WikiLinks wikilinks = new WikiLinks();
    TreeMap<String, HashSet> Attribute_Dependency = new TreeMap();

    Relationship relationship;
    // END SNIPPET: vars

    // START SNIPPET: createReltype
    private static enum RelTypes implements RelationshipType {
        MEMBER_OF, TRANSITION, USES, CARDINALITY, PROPERTY_OF, HAT_RECHTLICHE_GRUNDLAGE, DERIVED_BY, REPORTED_ON, HAT_MELDEVERPFLICHTUNG//, HAS_ROLE, HAS_PERMISSION
    }

    // END SNIPPET: createReltype
    public void addDependency(String a, String b) {

        HashSet x = Attribute_Dependency.get(a);

        if (x == null) {
            x = new HashSet();
            x.add(b);
            Attribute_Dependency.put(a, x);
        } else {
            x.add(b);
            //Attribute_Dependency.put(a,x);
        }
    }

    public static void main(final String[] args) {
        System.out.println("Starting");

        Wiki2Neo4j hello = new Wiki2Neo4j();

        HTMLParser wikiparser = new HTMLParser("frischwo01", "winter2014");

        WikiLinks wikilinks = new WikiLinks();

        String SC_Attribute_link = wikilinks.sc_attribute_link;
        String BC_Entitaeten_link = "https://www.myoenb.com/wiki/display/TES/.Entitaeten+des+Basic+Cubes+v2.0";
        String BC_Attribute_link = wikilinks.basiccubeatttribute;
        String Meldekonzepte_link = wikilinks.meldekonzepte_link;
        String SC_Algorithmen_link = "https://www.myoenb.com/wiki/display/TES/.Algorithmen+v3.11";
        String BC_Algorithmen_link = "https://www.myoenb.com/wiki/display/TES/.Algorithmen+des+Basic+Cubes+v3.11";
        //working
        //      String SC_Attribute_link = "https://www.myoenb.com/wiki/display/TES/.Smart+Cube+Attribute+v2.0";
        //      String BC_Entitaeten_link = "https://www.myoenb.com/wiki/display/TES/.Entitaeten+des+Basic+Cubes+v2.0";
        //      String BC_Attribute_link = "https://www.myoenb.com/wiki/display/TES/.Attribute+des+Basic+Cubes+v2.0";
        //      String Meldekonzepte_link = wikilinks.meldekonzepte_link;
        //      String SC_Algorithmen_link = "https://www.myoenb.com/wiki/display/TES/.Algorithmen+v0.00";
        //      String BC_Algorithmen_link = "https://www.myoenb.com/wiki/display/TES/.Algorithmen+des+Basic+Cubes+v1.1";

        //String SmartCubes_link = "https://www.myoenb.com/wiki/display/TES/.Smart+Cubes+Metabeschreibung+v1.2";

        GenerateSCSubset gebsubset = new GenerateSCSubset();

        ArrayList<Cube> all_cubes = new ArrayList();

        gebsubset.setup_all_Cubes(all_cubes);

        boolean parseCL = true;

        deleteFileOrDirectory(new File(DB_PATH));//loescht Graph Database

        //Initialisiere Datenbank am Anfang
        hello.graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
        registerShutdownHook(hello.graphDb);

        boolean parsing_false = true;
        ArrayList codelisteArrayList = null;

        if (parseCL) {
            while (parsing_false) {
                try {
                    codelisteArrayList = wikiparser
                            .Codelisten("https://www.myoenb.com/wiki/display/TES/.Codelisten+des+Basic+Cubes+v2.0");
                    if (codelisteArrayList.size() > 1)
                        parsing_false = false;
                } catch (Exception e) {
                    System.out.println(e.toString());
                }
            }

            for (int i = 0; i < codelisteArrayList.size(); i++) {
                Codeliste codeliset = (Codeliste) codelisteArrayList.get(i);
                System.out.println("adding Codelist");
                hello.addCodeliste2Db(codeliset);
            }
        }

        TreeMap<String, TreeMap> SmartCubes = new TreeMap(); //wikiparser.ParseObject(SmartCubes_link,"-Cube");
        TreeMap<String, TreeMap> SC_Attribute = wikiparser.ParseObject(SC_Attribute_link, "_");
        TreeMap<String, TreeMap> BC_Attribute = wikiparser.ParseObject(BC_Attribute_link, "_");
        TreeMap<String, TreeMap> BCEntitaeten = wikiparser.ParseObject(BC_Entitaeten_link, "_");
        TreeMap<String, TreeMap> Meldekonzepte = wikiparser.ParseObject(Meldekonzepte_link, "_");
        TreeMap<String, TreeMap> SC_Algorithmen = wikiparser.ParseObject(SC_Algorithmen_link, "_");
        TreeMap<String, TreeMap> BC_Algorithmen = wikiparser.ParseObject(BC_Algorithmen_link, "_");

        //      TreeMap<String,String> scattribut1 = new TreeMap();
        //      scattribut1.put("Bezeichnung des Smart Cube Attributs", "XYZ");
        //      TreeMap<String,String> bcattribut1 = new TreeMap();
        //      bcattribut1.put("Bezeichnung des BC Attributs", "ABC");
        //      //TreeMap<String, TreeMap> SC_Attribute = new TreeMap();
        //      TreeMap<String, TreeMap> BC_Attribute = new TreeMap();
        //      //SC_Attribute.put("scattribut1", scattribut1);
        //      BC_Attribute.put("bcattribut1", bcattribut1);

        TreeMap<String, String> BC = new TreeMap();
        BC.put("name", "BasicCube");

        TreeMap<String, TreeMap> test = new TreeMap();
        test.put("Basic Cube", BC);
        hello.addNodes2Db("BasicCube", "name", test);

        for (int i = 0; i < all_cubes.size(); i++) {
            Cube cube = all_cubes.get(i);
            TreeMap<String, String> dummy = new TreeMap();
            dummy.put("Bezeichnung des Smart Cubes", cube.getCubelongName());
            SmartCubes.put(cube.getCubelongName(), dummy);
        }

        hello.addNodes2Db("SmartCube", "Bezeichnung des Smart Cubes", SmartCubes);
        hello.addNodes2Db("SCAttribut", "Bezeichnung des Smart Cube Attributs", SC_Attribute);
        hello.addNodes2Db("BCAttribut", "Bezeichnung des BC Attributs", BC_Attribute);
        hello.addNodes2Db("Meldekonzept", "Bezeichnung des Meldekonzepts", Meldekonzepte);
        hello.addNodes2Db("BCEntitaet", "Name der Entitaet", BCEntitaeten);
        hello.addNodes2Db("SCAlgorithmen", "Bezeichnung des Algorithmus", SC_Algorithmen);
        hello.addNodes2Db("BCAlgorithmen", "Bezeichnung des Algorithmus", BC_Algorithmen);

        hello.addCubeProperties(all_cubes);

        System.out.println("Adding addiional nodes");

        hello.connectEnititestoAttributes("BCEntitaet", "Beschreibende Attribute", RelTypes.MEMBER_OF, -1);

        hello.connectEnititestoAttributes("Codeliste", "Kommtvorin", RelTypes.MEMBER_OF, 1);

        //hello.connectEnititestoAttributes("SCAttribut","Algorithmus/Entstehung/Bildung",RelTypes.TRANSITION,-1);

        //use of an anominous class -> in future lamdba expression   
        hello.connectObjecttoObject("SCAttribut", "Algorithmus/Entstehung/Bildung", RelTypes.TRANSITION, -1,
                new Executable() {
                    @Override
                    public void execute(Node hitnode, org.neo4j.kernel.EmbeddedGraphDatabase graphDb,
                            TreeMap<String, Node> string_node, String x) {
                        // TODO Auto-generated method stub
                        if (x.contains("1:1")) {
                            for (String key : string_node.keySet()) {
                                if (x.contains(key.toString())) {
                                    Node nodex = string_node.get(key);
                                    Relationship relationship = hitnode.createRelationshipTo(nodex,
                                            RelTypes.TRANSITION);
                                    hello.addDependency((String) hitnode.getProperty("name"),
                                            (String) nodex.getProperty("name"));
                                    //hier direkte Ueberleitung einfuehren
                                    //                         Node ueberleitung_node = string_node.get("1zu1Ueberleitung");
                                    //                         
                                    //                         if (ueberleitung_node == null){
                                    //                            ueberleitung_node = graphDb.createNode((org.neo4j.graphdb.Label) DynamicLabel.label("SCAlgorithmen"));
                                    //                            ueberleitung_node.setProperty("name", "1zu1Ueberleitung");
                                    //                            ueberleitung_node.setProperty("Bezeichnung des Algorithmus","1zu1Ueberleitung");
                                    //                            string_node.put("1zu1Ueberleitung", ueberleitung_node);
                                    //                         }
                                    //              
                                    //                         relationship = hitnode.createRelationshipTo(ueberleitung_node, RelTypes.DERIVED_BY);                                                  
                                    //                         relationship = ueberleitung_node.createRelationshipTo(nodex, RelTypes.USES);

                                }
                            }
                        } else {
                            //Attribut wird abgeleitet
                            try (Transaction tx = graphDb.beginTx()) {
                                IndexManager indexMan = graphDb.index();
                                Index<Node> index = indexMan.forNodes("SCAlgorithmen");
                                IndexHits<Node> hits = index.get("SCAlgorithmen", "xyz");

                                String parts[] = x.split("\\(");
                                String part1 = parts[0].replace(" ", "");

                                try {
                                    for (Node bcalgos : hits) {
                                        try {
                                            String name = (String) bcalgos
                                                    .getProperty("Bezeichnung des Algorithmus");

                                            if (x.replace(" ", "").contains(name)) {//(x.contains(name)){
                                                Relationship relationship = hitnode.createRelationshipTo(bcalgos,
                                                        RelTypes.DERIVED_BY);
                                                hello.addDependency((String) hitnode.getProperty("name"),
                                                        (String) bcalgos.getProperty("name"));

                                                //relationship.setProperty( "message", "brave Neo4j");
                                            }
                                        } catch (Exception e) {
                                            System.out.println(e.toString());
                                        }
                                    } //end node iteration
                                } finally {
                                    hits.close();
                                }
                                tx.success();
                            }
                            //ende Attribut wird abgeleitet   
                        }
                    }

                });

        hello.connectObjecttoObject("Meldekonzept", "Formale Beschreibung", RelTypes.USES, -1, new Executable() {
            //Verbinde die SC Algorithmen - aber ausschlielich mit Basic Cube Attributen
            @Override
            public void execute(Node hitnode, org.neo4j.kernel.EmbeddedGraphDatabase graphDb,
                    TreeMap<String, Node> string_node, String x) {
                // TODO Auto-generated method stub                     
                try (Transaction tx = graphDb.beginTx()) {
                    IndexManager indexMan = graphDb.index();
                    Index<Node> index = indexMan.forNodes("BCAttribut");
                    IndexHits<Node> hits = index.get("BCAttribut", "xyz");

                    try {
                        for (Node bcattribut : hits) {
                            try {
                                String name = (String) bcattribut.getProperty("Bezeichnung des BC Attributs");

                                if (x.contains(name)) {//(x.contains(name)){
                                    Relationship relationship = hitnode.createRelationshipTo(bcattribut,
                                            RelTypes.USES);
                                    hello.addDependency((String) hitnode.getProperty("name"),
                                            (String) bcattribut.getProperty("name"));

                                    //relationship.setProperty( "message", "brave Neo4j");
                                }
                            } catch (Exception e) {
                                System.out.println(e.toString());
                            }
                        } //end node iteration
                    } finally {
                        hits.close();
                    }
                    tx.success();
                }
                //ende Attribut wird abgeleitet   

            }

        });

        hello.connectObjecttoObject("SCAlgorithmen", "Formale Beschreibung", RelTypes.USES, -1, new Executable() {
            //Verbinde die SC Algorithmen - aber ausschlielich mit Basic Cube Attributen
            @Override
            public void execute(Node hitnode, org.neo4j.kernel.EmbeddedGraphDatabase graphDb,
                    TreeMap<String, Node> string_node, String x) {
                // TODO Auto-generated method stub                     
                try (Transaction tx = graphDb.beginTx()) {
                    IndexManager indexMan = graphDb.index();
                    Index<Node> index = indexMan.forNodes("BCAttribut");
                    IndexHits<Node> hits = index.get("BCAttribut", "xyz");

                    try {
                        for (Node bcattribut : hits) {
                            try {
                                String name = (String) bcattribut.getProperty("Bezeichnung des BC Attributs");

                                if (x.contains(name)) {//(x.contains(name)){
                                    Relationship relationship = hitnode.createRelationshipTo(bcattribut,
                                            RelTypes.USES);
                                    hello.addDependency((String) hitnode.getProperty("name"),
                                            (String) bcattribut.getProperty("name"));
                                    //relationship.setProperty( "message", "brave Neo4j");
                                }
                            } catch (Exception e) {
                                System.out.println(e.toString());
                            }
                        } //end node iteration
                    } finally {
                        hits.close();
                    }
                    tx.success();
                }
                //ende Attribut wird abgeleitet   

            }

        });

        //hello.connectEnititestoAttributes("BCAlgorithmen","Formale Beschreibung",RelTypes.USES);

        hello.connectEnititestoAttributes("BCAlgorithmen", "Kommt vor in/wird verwendet fr", RelTypes.USES, 1);

        //hello.connectEnititestoAttributes("SCAlgorithmen","Formale Beschreibung",RelTypes.USES,1);

        hello.connectEnitites_to_Node("BCEntitaet", "BasicCube", RelTypes.MEMBER_OF);

        hello.connectCubetoAttributes(all_cubes, RelTypes.MEMBER_OF);

        hello.graphDb.shutdown();

        System.out.println("Check" + hello.Attribute_Dependency.toString());

        JSONObject json_dep = new JSONObject();

        for (String key : hello.Attribute_Dependency.keySet()) {
            HashSet x = hello.Attribute_Dependency.get(key);
            java.util.Iterator it = x.iterator();
            while (it.hasNext()) {
                try {
                    json_dep.append(key, (String) it.next());
                    //json_dep.put(key, (String) it.next());
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }

        String content = json_dep.toString();

        try {

            //String content = json_smartcube.toString();

            File file = new File("C://Users//frisch//Desktop//json_export" + "//" + "Cube_Dependency.json");

            // if file doesnt exists, then create it
            if (!file.exists()) {
                file.createNewFile();
            }

            FileWriter fw = new FileWriter(file.getAbsoluteFile());
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(content);
            bw.close();

            System.out.println("Done");

        } catch (IOException e) {
            e.printStackTrace();
        }

        System.out.println("Ende");

        //}

        //hello.createDb();
        //hello.addNodes2Db(BCAttribute);
        //hello.removeData();

    }

    void addCubeProperties(ArrayList<Cube> all_cubes) {
        //graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
        registerShutdownHook(graphDb);
        try (Transaction tx = graphDb.beginTx()) {
            for (int i = 0; i < all_cubes.size(); i++) {//Iteration ber alle Cubes
                Cube cube = all_cubes.get(i);
                Node BAT_node = string_node.get(cube.getMeldetermin() + "BAT");
                Node cube_node = string_node.get(cube.getCubelongName());
                Node metacube_node = string_node.get(cube.getMetaCube());

                cube_node.setProperty("Meldetermin", cube.getMeldetermin());
                cube_node.setProperty("MetaCube", cube.getMetaCube());

                if (cube.getMeldeverpflichtungen().size() > 0) {
                    java.util.Iterator it = cube.getMeldeverpflichtungen().iterator();
                    while (it.hasNext()) {
                        String Meldeverpflichtung = (String) it.next();
                        Node meldeverpflichtung_node = string_node.get(Meldeverpflichtung);
                        if (meldeverpflichtung_node == null) {
                            meldeverpflichtung_node = graphDb
                                    .createNode((org.neo4j.graphdb.Label) DynamicLabel.label("Meldeverpflichtung"));
                            string_node.put(Meldeverpflichtung, meldeverpflichtung_node);
                        }
                        meldeverpflichtung_node.setProperty("name", Meldeverpflichtung);
                        meldeverpflichtung_node.setProperty("Bezeichnung der Meldeverpflichtung",
                                Meldeverpflichtung);
                        relationship = cube_node.createRelationshipTo(meldeverpflichtung_node,
                                RelTypes.HAT_MELDEVERPFLICHTUNG);
                    }
                }

                if (BAT_node == null) {
                    BAT_node = graphDb.createNode((org.neo4j.graphdb.Label) DynamicLabel.label("Meldetermin"));
                    BAT_node.setProperty("name", cube.getMeldetermin() + "BAT");
                    BAT_node.setProperty("Meldetermin", cube.getMeldetermin());
                    string_node.put(cube.getMeldetermin() + "BAT", BAT_node);
                    relationship = cube_node.createRelationshipTo(BAT_node, RelTypes.REPORTED_ON);
                } else {
                    relationship = cube_node.createRelationshipTo(BAT_node, RelTypes.REPORTED_ON);
                }

                if (metacube_node == null) {
                    metacube_node = graphDb.createNode((org.neo4j.graphdb.Label) DynamicLabel.label("MetaCube"));
                    metacube_node.setProperty("name", cube.getMetaCube());
                    string_node.put(cube.getMetaCube(), metacube_node);
                    relationship = cube_node.createRelationshipTo(metacube_node, RelTypes.MEMBER_OF);
                } else {
                    relationship = cube_node.createRelationshipTo(metacube_node, RelTypes.MEMBER_OF);
                }

            }

            //          Node EBA_ITS = graphDb.createNode((org.neo4j.graphdb.Label) DynamicLabel.label("Gesetz"));
            //          EBA_ITS.setProperty("Bezeichnung", "EBA ITS");
            //          EBA_ITS.setProperty("Text", "EBA Implementing Technical Standards on supervisory reporting under Regulation (EU) No 575/2013");
            //          EBA_ITS.setProperty("Regulation","575/2013");
            //          Node CRR = graphDb.createNode((org.neo4j.graphdb.Label) DynamicLabel.label("Gesetz"));
            //          CRR.setProperty("Bezeichnung", "CRR");
            //          CRR.setProperty("Text", "Verordnung (EU) Nr. 575/2013 des Europischen Parlaments und des Rates vom 26. Juni 2013 ber Aufsichtsanforderungen an Kreditinstitute und Wertpapierfirmen und zur nderung der Verordnung (EU) Nr. 646/2012");
            //          CRR.setProperty("Regulation","646/2012");
            //          Node ESVG = graphDb.createNode((org.neo4j.graphdb.Label) DynamicLabel.label("Gesetz"));
            //          ESVG.setProperty("Bezeichnung", "ESVG");
            //          ESVG.setProperty("Text", "Europischen System Volkswirtschaftlicher Gesamtrechnungen auf nationaler und regionaler Ebene in der Europischen Union (ESA_2010)");
            //          ESVG.setProperty("Regulation","549/2013");
            //          
            //          Node EZB_IF_STATISTIK = graphDb.createNode((org.neo4j.graphdb.Label) DynamicLabel.label("Gesetz"));
            //          EZB_IF_STATISTIK.setProperty("Bezeichnung", "EZB_IF STATISTIK");
            //          EZB_IF_STATISTIK.setProperty("Text", "Verordnung (EU) Nr. 1073/2013 der Europischen Zentralbank vom 18. Oktober 2013 ber die Statistik ber Aktiva und Passiva von Investmentfonds (Neufassung) (EZB/2013/38)");
            //          EZB_IF_STATISTIK.setProperty("Regulation","1073/2013");
            //          
            //          Node MONSTAT = graphDb.createNode((org.neo4j.graphdb.Label) DynamicLabel.label("Gesetz"));
            //          MONSTAT.setProperty("Bezeichnung", "MONSTAT");
            //          MONSTAT.setProperty("Text", "Verordnung (EU) Nr. 1071/2013 der Europischen Zentralbank vom 24.September 2013 ber die Bilanz des Sektors der monetren Finanzinstitute (EZB/2013/33)");
            //          MONSTAT.setProperty("Regulation","1071/2013");
            //
            //          Node ZINSTAT = graphDb.createNode((org.neo4j.graphdb.Label) DynamicLabel.label("Gesetz"));
            //          ZINSTAT.setProperty("Bezeichnung", "ZINSSTAT");
            //          ZINSTAT.setProperty("Text", "Verordnung (EU) Nr. 1072/2013 der Europischen Zentralbank vom 24. September 2013 ber die Statistik ber die von monetren Finanzinstituten angewandten Zinsstze fr Einlagen und Kredite gegenber privaten Haushalten und nichtfinanziellen Kapitalgesellschaften (EZB/2013/34)");
            //          ZINSTAT.setProperty("Regulation","1072/2013");
            //          
            //          Node NBGESETZ = graphDb.createNode((org.neo4j.graphdb.Label) DynamicLabel.label("Gesetz"));
            //          NBGESETZ.setProperty("Bezeichnung", "Nationalbankgesetz");
            //          NBGESETZ.setProperty("Text", "Nationalbankgesetz  44 Abs. 1");
            //          NBGESETZ.setProperty("Regulation"," 44 Abs. 1");
            //          
            //          
            //            Index<Node> nodeIndex = graphDb.index().forNodes("Gesetz");       
            //            nodeIndex.add(EBA_ITS, "Gesetz", "xyz");
            //            nodeIndex.add(CRR, "Gesetz", "xyz");
            //            nodeIndex.add(ESVG, "Gesetz", "xyz");
            //            nodeIndex.add(EZB_IF_STATISTIK, "Gesetz", "xyz");
            //            nodeIndex.add(MONSTAT, "Gesetz", "xyz");
            //            nodeIndex.add(ZINSTAT, "Gesetz", "xyz");
            //            nodeIndex.add(NBGESETZ, "Gesetz", "xyz");
            //            
            //            IndexManager indexMan = graphDb.index();
            //           Index<Node> index = indexMan.forNodes("Gesetz");
            //            IndexHits<Node> hits = index.get("Gesetz", "xyz");
            //             
            //            try
            //            {
            //                for ( Node node : hits )
            //                {
            //                   String text = (String) node.getProperty("Text");
            //                  for (String key:SmartCubes.keySet()){
            //                     TreeMap<String, String> cube = SmartCubes.get(key);
            //                     String name = cube.get("Bezeichnung des Smart Cubes");
            //                     Node cube_node = string_node.get(name);
            //                     String gesetzliche_grundlage = (String) cube_node.getProperty("Gesetzliche Grundlage");
            //                     if (gesetzliche_grundlage.contains(text)) relationship = cube_node.createRelationshipTo(node, RelTypes.HAT_RECHTLICHE_GRUNDLAGE);
            //                  }    
            //                }
            //                
            //            }
            //            finally
            //            {
            //                hits.close();
            //            }
            //            
            //          Node MP = graphDb.createNode((org.neo4j.graphdb.Label) DynamicLabel.label("Meldeperiodizitt"));
            //          MP.setProperty("Meldeperiodizitt", "monatlich");
            //          
            //          Node MT = graphDb.createNode((org.neo4j.graphdb.Label) DynamicLabel.label("Meldetermin"));;
            //          MT.setProperty("Meldetermin", "10. Bankarbeitstag");
            //          
            //          Node MW = graphDb.createNode((org.neo4j.graphdb.Label) DynamicLabel.label("Meldewhrung"));;
            //          MW.setProperty("Meldewhrung", "EUR");        
            //            
            //          for (String key:SmartCubes.keySet()){
            //             TreeMap<String, String> cube = SmartCubes.get(key);
            //             String name = cube.get("Bezeichnung des Smart Cubes");
            //             Node cube_node = string_node.get(name);
            //             if (cube_node!= null){
            //                  relationship = MP.createRelationshipTo(cube_node, RelTypes.PROPERTY_OF );
            //                  relationship = MT.createRelationshipTo(cube_node, RelTypes.PROPERTY_OF );
            //                  relationship = MW.createRelationshipTo(cube_node, RelTypes.PROPERTY_OF );
            //                  //Test
            //                  relationship = cube_node.createRelationshipTo(MONSTAT, RelTypes.HAT_RECHTLICHE_GRUNDLAGE );
            //                  relationship = cube_node.createRelationshipTo(NBGESETZ, RelTypes.HAT_RECHTLICHE_GRUNDLAGE );
            //             }
            //             
            //          }
            tx.success();
        }
    }

    void connectEnitites_to_Node(String type, String nodename, RelTypes Rel) {

        //       boolean getDB = false;
        // 
        //       while(getDB == false){
        //          try{
        //             graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
        //             getDB = true;
        //          }catch(Exception e){
        //             System.out.println(e.toString());
        //          }
        //       }

        registerShutdownHook(graphDb);

        Node x = (Node) string_node.get(nodename);

        if (x != null) {

            try (Transaction tx = graphDb.beginTx()) {
                IndexManager indexMan = graphDb.index();
                Index<Node> index = indexMan.forNodes(type);
                IndexHits<Node> hits = index.get(type, "xyz");

                try {
                    for (Node node : hits) {
                        relationship = node.createRelationshipTo(x, Rel);
                    }

                } finally {
                    hits.close();
                }
                tx.success();
            }

        }

    }

    void connectObjecttoObject(String type, String parsefield, RelTypes rel, int direction, Executable exec) {
        //      graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
        //      registerShutdownHook(graphDb);
        try (Transaction tx = graphDb.beginTx()) {

            IndexManager indexMan = graphDb.index();
            Index<Node> index = indexMan.forNodes(type);
            IndexHits<Node> hits = index.get(type, "xyz");
            try {
                for (Node node : hits) {

                    try {
                        String text = (String) node.getProperty(parsefield);
                        // Code auslagern
                        exec.execute(node, (EmbeddedGraphDatabase) graphDb, string_node, text);
                    } catch (Exception e) {
                        System.out.println(e.toString());
                    }

                } //end node iteration
            } finally {
                hits.close();
            }

            tx.success();

        }
    }

    void connectEnititestoAttributes(String type, String parsefield, RelTypes rel, int direction) {
        //        graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
        //        registerShutdownHook(graphDb);
        try (Transaction tx = graphDb.beginTx()) {
            IndexManager indexMan = graphDb.index();
            Index<Node> index = indexMan.forNodes(type);
            IndexHits<Node> hits = index.get(type, "xyz");
            try {
                for (Node node : hits) {

                    try {
                        String beschreibende_attribute = (String) node.getProperty(parsefield);
                        for (String key : string_node.keySet()) {
                            if (beschreibende_attribute.contains(key)) {
                                Node nodex = (Node) string_node.get(key);
                                if (direction == 1)
                                    relationship = node.createRelationshipTo(nodex, rel);
                                if (direction == -1)
                                    relationship = nodex.createRelationshipTo(node, rel);
                                //relationship.setProperty( "message", "brave Neo4j");
                            }

                        }
                    } catch (Exception e) {
                        System.out.println(e.toString());
                    }

                } //end node iteration
            } finally {
                hits.close();
            }
            tx.success();
        }

    }

    void connectCubetoAttributes(ArrayList<Cube> all_cubes, RelTypes rel) {
        registerShutdownHook(graphDb);
        try (Transaction tx = graphDb.beginTx()) {
            for (int i = 0; i < all_cubes.size(); i++) {

                Cube cube = all_cubes.get(i);
                Node cube_node = (Node) string_node.get(cube.getCubelongName());

                HashSet SC_Attribute = new HashSet();

                for (String key : cube.Meldekonzept_SCDimensionen.keySet()) {

                    HashSet dummy = cube.Meldekonzept_SCDimensionen.get(key);
                    //Node meldekonzept_node = (Node) string_node.get(key.toString());
                    if (dummy != null)
                        SC_Attribute.addAll(dummy);

                    //                 if (meldekonzept_node!=null){
                    //                    relationship = meldekonzept_node.createRelationshipTo(cube_node, rel);   
                    //                    java.util.Iterator it = dummy.iterator();           
                    //                      while(it.hasNext()){
                    //                         String sc_attribut_name = (String) it.next();
                    //                         Node sc_attribut = (Node) string_node.get(sc_attribut_name);                   
                    //                           if (sc_attribut != null & cube_node != null) relationship = sc_attribut.createRelationshipTo(cube_node, rel);//meldekonzept_node
                    //                      }     
                    //                 }

                } //Iteration ueber MK

                java.util.Iterator it = SC_Attribute.iterator();
                while (it.hasNext()) {
                    String sc_attribut_name = (String) it.next();
                    Node sc_attribut_node = (Node) string_node.get(sc_attribut_name);
                    if (sc_attribut_node != null & cube_node != null)
                        relationship = sc_attribut_node.createRelationshipTo(cube_node, rel);//meldekonzept_node
                }
            }
            tx.success();
        }

    }

    void addCodeliste2Db(Codeliste codeliste) {
        // START SNIPPET: startDb
        //       boolean getDB = false;
        //        
        //       while(getDB == false){
        //          try{
        //             graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
        //             getDB = true;
        //          }catch(Exception e){
        //             System.out.println(e.toString());
        //          }
        //       }        
        //       
        //       registerShutdownHook( graphDb );
        //org.neo4j.graphdb.Label label = DynamicLabel.label("Codeliste");
        try (Transaction tx = graphDb.beginTx()) {
            Index<Node> nodeIndex = graphDb.index().forNodes("Codeliste");
            Node node_coldeiste = graphDb.createNode((org.neo4j.graphdb.Label) DynamicLabel.label("Codeliste"));
            node_coldeiste.setProperty("Name", codeliste.Name);
            node_coldeiste.setProperty("ExcludeState", codeliste.ExcludeState);
            node_coldeiste.setProperty("Kommtvorin", codeliste.Kommtvorin);
            nodeIndex.add(node_coldeiste, "Codeliste", "xyz");
            for (int i = 1; i < codeliste.Codes.size(); i++) {
                String[] code = (String[]) codeliste.Codes.get(i);
                if (code[0] != null && code[1] != null && code[2] != null) {
                    Node node_code = graphDb.createNode((org.neo4j.graphdb.Label) DynamicLabel.label("Code"));
                    node_code.setProperty("Code", code[0]);
                    node_code.setProperty("Codebezeichnung", code[1]);
                    node_code.setProperty("Beschreibung", code[2]);
                    relationship = node_code.createRelationshipTo(node_coldeiste, RelTypes.MEMBER_OF);
                    //relationship.setProperty( "message", "brave Neo4j " );
                }
            }
            tx.success();
        }
        //graphDb.shutdown();
    }

    void addRelation(String type1, String type2) {

        graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
        registerShutdownHook(graphDb);
        try (Transaction tx = graphDb.beginTx()) {

            IndexManager indexMan = graphDb.index();
            Index<Node> index = indexMan.forNodes("timeline1");

            IndexHits<Node> hits = index.get("timeline1", "xyz");

            try {
                for (Node node : hits) {
                    // do something with the hit
                }
            } finally {
                hits.close();
            }

            Index<Node> nodeIndex1 = graphDb.index().forNodes(type1);

            Index<Node> nodeIndex2 = graphDb.index().forNodes(type2);

            for (Node node : graphDb.getAllNodes()) {

            }

            tx.success();
        }
        graphDb.shutdown();
    }

    public void addNodeProperty(TreeMap<String, String> treemap, String property, Node node) {
        String string = treemap.get(property);
        if (string != null)
            node.setProperty(property, string);
    }

    void addNodes2Db(String type, String string_to_parse, TreeMap<String, TreeMap> Object) {
        // START SNIPPET: startDb

        //        graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
        //        registerShutdownHook(graphDb);

        org.neo4j.graphdb.Label label = DynamicLabel.label(type);

        try (Transaction tx = graphDb.beginTx()) {
            Index<Node> nodeIndex = graphDb.index().forNodes(type);
            //IndexManager indexMan = graphDb.index();
            //Index<Node> index = indexMan.forNodes("timeline1");

            //Node cube = graphDb.createNode((org.neo4j.graphdb.Label) DynamicLabel.label("BasicCube"));

            for (String key : Object.keySet()) {
                TreeMap<String, String> BCAttribut = Object.get(key);
                Node node = graphDb.createNode(label);

                //checking               

                String name = BCAttribut.get(string_to_parse);

                node.setProperty("name", key);

                addNodeProperty(BCAttribut, "ExcludeState", node);
                addNodeProperty(BCAttribut, "Datentyp", node);
                addNodeProperty(BCAttribut, "Feldlnge", node);
                addNodeProperty(BCAttribut, "Beschreibende Attribute", node);
                addNodeProperty(BCAttribut, "Algorithmus/Entstehung/Bildung", node);
                addNodeProperty(BCAttribut, "Bildung", node);

                //Smart Cubes
                addNodeProperty(BCAttribut, "Gesetzliche Grundlage", node);
                addNodeProperty(BCAttribut, "Melderkreis", node);
                addNodeProperty(BCAttribut, "Meldeperiodizitt", node);
                addNodeProperty(BCAttribut, "Meldetermin", node);
                addNodeProperty(BCAttribut, "Meldeperiode", node);
                addNodeProperty(BCAttribut, "Meldewhrung", node);
                addNodeProperty(BCAttribut, "Formale Beschreibung", node);
                addNodeProperty(BCAttribut, "Kommt vor in/wird verwendet fr", node);

                nodeIndex.add(node, type, "xyz");
                if (name != null)
                    string_node.put(name, node);

                //System.out.println(":"+name+":");

                if (name != null)
                    node.setProperty(string_to_parse, name);
                //Zu Testzwecken
                //relationship = cube.createRelationshipTo(node, RelTypes.MEMBER_OF );
                //relationship.setProperty( "message", "brave Neo4j " );
            }
            tx.success();
        }

        //graphDb.shutdown();
    }

    void createDb() {
        deleteFileOrDirectory(new File(DB_PATH));
        // START SNIPPET: startDb
        graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
        registerShutdownHook(graphDb);
        // END SNIPPET: startDb

        // START SNIPPET: transaction
        try (Transaction tx = graphDb.beginTx()) {
            // Database operations go here
            // END SNIPPET: transaction
            // START SNIPPET: addData

            IndexManager index = graphDb.index();
            Index<Node> actors = index.forNodes("actors");
            Index<Node> movies = index.forNodes("movies");
            RelationshipIndex roles = index.forRelationships("roles");

            Schema schema = graphDb.schema();

            //            IndexDefinition  indexDefinition = schema.indexFor( DynamicLabel.label( "User" ))
            //                       .on( "username" )
            //                       .create();

            org.neo4j.graphdb.Label label = DynamicLabel.label("Beaver");

            firstNode = graphDb.createNode();
            firstNode.setProperty("message", "Hello, ");
            secondNode = graphDb.createNode();
            secondNode.setProperty("message", "World!");

            thirdNode = graphDb.createNode(label);
            thirdNode.setProperty("Name", "Wolfgang Frisch");
            thirdNode.setProperty("Alter", 31);

            actors.add(thirdNode, "Name", thirdNode.getProperty("Name"));

            relationship = firstNode.createRelationshipTo(secondNode, RelTypes.MEMBER_OF);
            relationship.setProperty("message", "brave Neo4j ");
            // END SNIPPET: addData

            // START SNIPPET: readData
            System.out.print(firstNode.getProperty("message"));
            System.out.print(relationship.getProperty("message"));
            System.out.print(secondNode.getProperty("message"));
            // END SNIPPET: readData

            greeting = ((String) firstNode.getProperty("message")) + ((String) relationship.getProperty("message"))
                    + ((String) secondNode.getProperty("message"));

            // START SNIPPET: transaction
            System.out.println("ENDE");

            tx.success();
        }
        // END SNIPPET: transaction
    }

    void removeData() {
        try (Transaction tx = graphDb.beginTx()) {
            // START SNIPPET: removingData
            // let's remove the data
            //firstNode.getSingleRelationship( RelTypes.KNOWS, Direction.OUTGOING ).delete();
            //firstNode.delete();
            //secondNode.delete();
            // END SNIPPET: removingData

            tx.success();
        }
    }

    void shutDown() {
        System.out.println();
        System.out.println("Shutting down database ...");
        // START SNIPPET: shutdownServer
        graphDb.shutdown();
        // END SNIPPET: shutdownServer
    }

    // START SNIPPET: shutdownHook
    private static void registerShutdownHook(final GraphDatabaseService graphDb) {
        // Registers a shutdown hook for the Neo4j instance so that it
        // shuts down nicely when the VM exits (even if you "Ctrl-C" the
        // running application).
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                graphDb.shutdown();
            }
        });
    }
    // END SNIPPET: shutdownHook

    private static void deleteFileOrDirectory(File file) {
        if (file.exists()) {
            if (file.isDirectory()) {
                for (File child : file.listFiles()) {
                    deleteFileOrDirectory(child);
                }
            }
            file.delete();
        }
    }
}