gt:                     + friendPath.endNode().getProperty("prefLabel") + "\n";
context: /*  Copyright (C) 2013 TUNCER Nurettin
  
      This program is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published by
      the Free Software Foundation; either version 2 of the License, or
      (at your option) any later version.
  
      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      GNU General Public License for more details.
  
      You should have received a copy of the GNU General Public License along
      with this program; if not, write to the Free Software Foundation, Inc.,
      51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   */
  package Neo4jOperations;
  
  import Main.Configuration;
  import Neo4jOperations.GraphDataBase.RelationTypes;
  import Object.RelationsList;
  import Object.XmlNode;
  import Utils.StringOperations;
  import java.util.ArrayList;
  import java.util.List;
  import org.apache.log4j.Level;
  import org.apache.log4j.Logger;
  import org.neo4j.graphdb.Direction;
  import org.neo4j.graphdb.GraphDatabaseService;
  import org.neo4j.graphdb.Node;
  import org.neo4j.graphdb.Path;
  import org.neo4j.graphdb.Relationship;
  import org.neo4j.graphdb.RelationshipType;
  import org.neo4j.graphdb.Transaction;
  import org.neo4j.graphdb.index.ReadableIndex;
  import org.neo4j.graphdb.traversal.Evaluators;
  import org.neo4j.graphdb.traversal.TraversalDescription;
  import org.neo4j.graphdb.traversal.Traverser;
  import org.neo4j.kernel.Traversal;
  
  /**
   *
   * @author nouri
   */
  public  class CreateRameauAndDeweyRelations {
  
      //private  final String DB_PATH = "DB/databaseNeo4j";
      private  final Logger LOG = Logger.getLogger(CreateRameauAndDeweyRelations.class.getName());
      private  GraphDatabaseService graphDb;
      private  Configuration conf;
      private  int matchKeywords = 0;
  
      public CreateRameauAndDeweyRelations(GraphDatabaseService Gb, Configuration pConf) {
          conf = pConf;
          graphDb = Gb;
      }
  
      public void start(ArrayList<XmlNode> xmlnodes) {
          //LOG.setLevel(Level.INFO);
  
          if (conf.getBoolean("create.rameau")) {
              LOG.info("CreateRameauAndDeweyRelations started");
  
  
  
              Transaction tx = graphDb.beginTx();
  
              try {
                  for (XmlNode xmlNode : xmlnodes) {
                      LOG.debug("-------------------Creation starts-----------------------------------");
                      Node mainNode = mainNodeCreation(xmlNode, graphDb);
                      createRelationships(mainNode, xmlNode.getRelations(), graphDb);
                      LOG.debug("-------------------Creation finished-----------------------------------\n");
                  }
                  tx.success();
              } finally {
                  tx.finish();
              }
  
  
  
              LOG.info("CreateRameauAndDeweyRelations finished");
          } else {
              LOG.info("Creation Rameau is: " + conf.getBoolean("create.rameau"));
          }
          //         
  //         shutDown(graphDb);
  
  //        Node test;
  //        test = findNodeByName("Cheval");
  //        
  //        LOG.info("id " +test.getId());
  //        ArrayList<Node> currentRelations = getNodeRelationsById(test.getId(), RelTypes.NARROWER);
  //        getNodeRelationsPrefLabel(currentRelations);
  //        currentRelations = getNodeRelationsByIdDirectonIncoming(test.getId(), RelTypes.NARROWER);
  //        getNodeRelationsPrefLabel(currentRelations);
  
  //        getBroaderNodeById(test.getId());
  //        getNarrowerNodeById(test.getId());
  //        getRelatedNodeById(test.getId());
          
      }
  
  
      private Node mainNodeCreation(XmlNode xmlNode, GraphDatabaseService graphDb) {
          Node currentNode = null;
          if (isNodeExist(xmlNode.getExternalId())) {
              if (getNodeUsingExternalID(xmlNode.getExternalId()) != null) {
                  LOG.debug("Main Node exists. Node ExternalID: " + xmlNode.getExternalId());
                  currentNode = getNodeUsingExternalID(xmlNode.getExternalId());
                  currentNode = updateMainNode(currentNode, xmlNode);
              }
          } else {
              LOG.debug("Main Node doesn't exist. Node will create. Node ExternalID: " + xmlNode.getExternalId());
              currentNode = createMainNode(xmlNode, graphDb);
          }
  
          return currentNode;
      }
  
      private  void compareWords(ArrayList<String> keywords) {
          ArrayList<String> nonmatchedKeywords = new ArrayList<>();
          matchKeywords = 0;
          int count = 0;
          for (String keyword : keywords) {
  
              if (isNodeExist(keyword)) {
                  matchKeywords++;
                  LOG.debug("Matched: " + matchKeywords + " / " + keywords.size());
              } else {
                  nonmatchedKeywords.add(keyword);
              }
              count++;
              LOG.debug("Count: " + count + " / " + keywords.size());
          }
  
          LOG.debug("There are " + matchKeywords + " Keywords matched with Rameau and There are " + nonmatchedKeywords.size() + " Keywords didn't Match");
          LOG.debug("List of nonmatched Keywords");
          printArray(nonmatchedKeywords);
  
      }
  
      private  void printArray(ArrayList<String> array) {
  
          for (String element : array) {
              LOG.debug(element);
          }
      }
  
      private  ArrayList<Node> getNodeRelationsById(long nodeID, RelationshipType type) {
          LOG.debug("Node ID: " + nodeID + " , RelationshipType: " + type);
          Iterable<Relationship> relations = graphDb.getNodeById(nodeID).getRelationships(Direction.OUTGOING, type);
          ArrayList<Node> currentRelations = new ArrayList<>();
          for (Relationship relationship : relations) {
              currentRelations.add(relationship.getEndNode());
          }
  
          return currentRelations;
      }
  
      private  ArrayList<Node> getNodeRelationsByIdDirectonIncoming(long nodeID, RelationshipType type) {
          LOG.debug("");
          LOG.debug("Node ID: " + nodeID + " , Incoming RelationshipType: " + type);
          LOG.debug("");
          Iterable<Relationship> relations = graphDb.getNodeById(nodeID).getRelationships(Direction.INCOMING, type);
          ArrayList<Node> currentRelations = new ArrayList<>();
          for (Relationship relationship : relations) {
              currentRelations.add(relationship.getStartNode());
          }
  
          return currentRelations;
      }
  
      private  void getNodeRelationsPrefLabel(ArrayList<Node> nodeRelationsList) {
          if (nodeRelationsList.isEmpty()) {
              LOG.debug("The list is empty");
          } else {
              for (Node node : nodeRelationsList) {
                  print("Node id: " + node.getId() + " Node prefLabel: " + node.getProperty("prefLabel"));
              }
          }
      }
  
      private  void getLinkedNodesById(long nodeID, final RelationTypes rel) {
          Iterable<Relationship> relations =
                  graphDb.getNodeById(nodeID).getRelationships(Direction.OUTGOING, rel);
          int count = 1;
          for (Relationship relationship : relations) {
              LOG.debug("count " + count);
              LOG.debug(printNodeBroaders(relationship.getEndNode()));
              count++;
          }
  
      }
  
      private  Traverser getBroaders(Node broader) {
          TraversalDescription td = Traversal.description().breadthFirst().relationships(GraphDataBase.RelationTypes.BROADER, Direction.OUTGOING).evaluator(Evaluators.excludeStartPosition());
          return td.traverse(broader);
      }
  
      private  Traverser getNarrowers(Node narrower) {
          TraversalDescription td = Traversal.description().breadthFirst().relationships(GraphDataBase.RelationTypes.NARROWER, Direction.OUTGOING).evaluator(Evaluators.excludeStartPosition());
          return td.traverse(narrower);
      }
  
      private  Traverser getRelated(Node related) {
          TraversalDescription td = Traversal.description().breadthFirst().relationships(GraphDataBase.RelationTypes.RELATED, Direction.OUTGOING).evaluator(Evaluators.excludeStartPosition());
          return td.traverse(related);
      }
  
      private  String printNodeBroaders(Node broader) {
  
          // START SNIPPET: friends-usage
          int numberOfBroaders = 0;
          String output = broader.getProperty("prefLabel") + "'s broaders:\n";
          Traverser broaderTraverser = getBroaders(broader);
          for (Path friendPath : broaderTraverser) {
              output += "At depth " + friendPath.length() + " => "
                      + friendPath.endNode().getProperty("prefLabel") + "\n";
              numberOfBroaders++;
          }
          output += "Number of broaders found: " + numberOfBroaders + "\n";
          // END SNIPPET: friends-usage
          return output;
      }
  
      private  String printNodeNarrowers(Node narrower) {
  
          // START SNIPPET: friends-usage
          int numberOfNarrowers = 0;
          String output = narrower.getProperty("prefLabel") + "'s narrowers:\n";
          Traverser broaderTraverser = getNarrowers(narrower);
          for (Path friendPath : broaderTraverser) {
              output += "At depth " + friendPath.length() + " => "
  