Java Code Examples for org.neo4j.graphdb.Node#addLabel()

The following examples show how to use org.neo4j.graphdb.Node#addLabel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnonymousNodeTagger.java    From SciGraph with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
  logger.info("Starting anonymous nodes tagger...");
  int taggedNodes = 0;
  Transaction tx = graphDb.beginTx();

  ResourceIterable<Node> allNodes = graphDb.getAllNodes();
  for (Node n : allNodes) {
    if (n.hasProperty(anonymousProperty)) {
      n.addLabel(OwlLabels.OWL_ANONYMOUS);
      taggedNodes++;
    }
    if (taggedNodes % batchCommitSize == 0) {
      tx.success();
      tx.close();
      tx = graphDb.beginTx();
    }
  }

  logger.info(taggedNodes + " nodes tagged.");
  tx.success();
  tx.close();
}
 
Example 2
Source File: QuestionInfo.java    From SnowGraph with Apache License 2.0 6 votes vote down vote up
public QuestionInfo(Node node, int id, String creationDate, int score, int viewCount, String body, int ownerUserId, String title, String tags, int acceptedAnswerId) {
    this.node = node;
    this.questionId = id;
    this.acceptedAnswerId = acceptedAnswerId;
    this.ownerUserId = ownerUserId;

    node.addLabel(Label.label(StackOverflowExtractor.QUESTION));

    node.setProperty(StackOverflowExtractor.QUESTION_ID, id);
    node.setProperty(StackOverflowExtractor.QUESTION_CREATION_DATE, creationDate);
    node.setProperty(StackOverflowExtractor.QUESTION_SCORE, score);
    node.setProperty(StackOverflowExtractor.QUESTION_VIEW_COUNT, viewCount);
    node.setProperty(StackOverflowExtractor.QUESTION_BODY, body);
    node.setProperty(StackOverflowExtractor.QUESTION_OWNER_USER_ID, ownerUserId);
    node.setProperty(StackOverflowExtractor.QUESTION_TITLE, title);
    node.setProperty(StackOverflowExtractor.QUESTION_TAGS, tags);

}
 
Example 3
Source File: GraphNodeUtil.java    From SnowGraph with Apache License 2.0 6 votes vote down vote up
public static void createSectionNode(SectionInfo section, Node node) {
    node.addLabel(Label.label(WordKnowledgeExtractor.DOCX_SECTION));
    if(section.getTitle() != null) node.setProperty(WordKnowledgeExtractor.SECTION_TITLE, section.getTitle());
    else node.setProperty(WordKnowledgeExtractor.SECTION_TITLE, "");
    node.setProperty(WordKnowledgeExtractor.SECTION_LAYER, section.getLayer());
    if(section.getSectionNumber() != null) node.setProperty(WordKnowledgeExtractor.SECTION_NUMBER, section.getSectionNumber());
    else node.setProperty(WordKnowledgeExtractor.SECTION_NUMBER, "");
    if(section.getUsageType() != null) node.setProperty(WordKnowledgeExtractor.SECTION_USAGE_TYPE, section.getUsageType());
    else node.setProperty(WordKnowledgeExtractor.SECTION_USAGE_TYPE, "");
    if(section.getPackageName() != null) node.setProperty(WordKnowledgeExtractor.SECTION_PACKAGE, section.getPackageName());
    else node.setProperty(WordKnowledgeExtractor.SECTION_PACKAGE, "");
    HashSet<String> sectionApis = section.getApiList();
    String nodeApiList = "";
    for(String api : sectionApis) {
        nodeApiList = nodeApiList + "\n" + api;
    }
    node.setProperty(WordKnowledgeExtractor.SECTION_APIS, nodeApiList);
    if(section.getProjectName() != null) node.setProperty(WordKnowledgeExtractor.SECTION_PROJECT_NAME, section.getProjectName());
    else node.setProperty(WordKnowledgeExtractor.SECTION_PROJECT_NAME, "");
}
 
Example 4
Source File: QaCommentInfo.java    From SnowGraph with Apache License 2.0 6 votes vote down vote up
public QaCommentInfo(Node node, int id, int parentId, int score, String text, String creationDate, int userId) {
    this.node = node;
    this.commentId = id;
    this.parentId = parentId;
    this.userId = userId;

    node.addLabel(Label.label(StackOverflowExtractor.COMMENT));

    node.setProperty(StackOverflowExtractor.COMMENT_ID, id);
    node.setProperty(StackOverflowExtractor.COMMENT_PARENT_ID, parentId);
    node.setProperty(StackOverflowExtractor.COMMENT_SCORE, score);
    node.setProperty(StackOverflowExtractor.COMMENT_TEXT, text);
    node.setProperty(StackOverflowExtractor.COMMENT_CREATION_DATE, creationDate);
    node.setProperty(StackOverflowExtractor.COMMENT_USER_ID, userId);

}
 
Example 5
Source File: BugzillaUtils.java    From SnowGraph with Apache License 2.0 6 votes vote down vote up
public static void creatBugzillaIssueNode(BugInfo bugInfo, Node node) {
    node.addLabel(Label.label(BugzillaExtractor.BUGZILLAISSUE));
    node.setProperty(BugzillaExtractor.ISSUE_BUGID, bugInfo.getBugId());
    node.setProperty(BugzillaExtractor.ISSUE_CREATIONTS, bugInfo.getCreationTs());
    node.setProperty(BugzillaExtractor.ISSUE_SHORTDESC, bugInfo.getShortDesc());
    node.setProperty(BugzillaExtractor.ISSUE_DELTATS, bugInfo.getDeltaTs());
    node.setProperty(BugzillaExtractor.ISSUE_CLASSIFICATION, bugInfo.getClassification());
    node.setProperty(BugzillaExtractor.ISSUE_PRODUCT, bugInfo.getProduct());
    node.setProperty(BugzillaExtractor.ISSUE_COMPONENT, bugInfo.getComponent());
    node.setProperty(BugzillaExtractor.ISSUE_VERSION, bugInfo.getVersion());
    node.setProperty(BugzillaExtractor.ISSUE_REPPLATFORM, bugInfo.getRepPlatform());
    node.setProperty(BugzillaExtractor.ISSUE_OPSYS, bugInfo.getOpSys());
    node.setProperty(BugzillaExtractor.ISSUE_BUGSTATUS, bugInfo.getBugStatus());
    node.setProperty(BugzillaExtractor.ISSUE_RESOLUTION, bugInfo.getResolution());
    node.setProperty(BugzillaExtractor.ISSUE_PRIORITY, bugInfo.getPriority());
    node.setProperty(BugzillaExtractor.ISSUE_BUGSEVERITIY, bugInfo.getBugSeverity());
    node.setProperty(BugzillaExtractor.ISSUE_REPROTER, bugInfo.getReporter());
    node.setProperty(BugzillaExtractor.ISSUE_REPROTERNAME, bugInfo.getReporterName());
    node.setProperty(BugzillaExtractor.ISSUE_ASSIGNEDTO, bugInfo.getAssignedTo());
    node.setProperty(BugzillaExtractor.ISSUE_ASSIGNEENAME, bugInfo.getAssignedToName());
}
 
Example 6
Source File: MboxHandler.java    From SnowGraph with Apache License 2.0 6 votes vote down vote up
private void createUserNode(Node mailNode, String userName, String userAddress, boolean sender) {
    Node userNode;
    if (!mailUserMap.containsKey(userAddress)) {
        userNode = db.createNode();
        userNode.addLabel(Label.label(MailListExtractor.MAILUSER));
        userNode.setProperty(MailListExtractor.MAILUSER_MAIL, userAddress);
        mailUserMap.put(userAddress, userNode);
    }
    userNode = mailUserMap.get(userAddress);
    if (!mailUserNameMap.containsKey(userAddress))
        mailUserNameMap.put(userAddress, new HashSet<>());
    mailUserNameMap.get(userAddress).add(userName);
    if (sender)
        mailNode.createRelationshipTo(userNode, RelationshipType.withName(MailListExtractor.MAIL_SENDER));
    else
        mailNode.createRelationshipTo(userNode, RelationshipType.withName(MailListExtractor.MAIL_RECEIVER));

}
 
Example 7
Source File: GitCommit.java    From SnowGraph with Apache License 2.0 5 votes vote down vote up
public Node createNode(GraphDatabaseService db){
    Node node=db.createNode();
    node.addLabel(Label.label(GitExtractor.COMMIT));
    node.setProperty(GitExtractor.COMMIT_ID,commitId);
    node.setProperty(GitExtractor.COMMIT_DATE,createDate);
    node.setProperty(GitExtractor.COMMIT_LOGMESSAGE,logMessage);
    node.setProperty(GitExtractor.COMMIT_CONTENT,content);
    return node;
}
 
Example 8
Source File: JavaCodeUtils.java    From SnowGraph with Apache License 2.0 5 votes vote down vote up
public static void createInterfaceNode(InterfaceInfo interfaceInfo, Node node) {
    node.addLabel(Label.label(JavaCodeExtractor.INTERFACE));
    node.setProperty(JavaCodeExtractor.INTERFACE_NAME, interfaceInfo.name);
    node.setProperty(JavaCodeExtractor.INTERFACE_FULLNAME, interfaceInfo.fullName);
    node.setProperty(JavaCodeExtractor.INTERFACE_SUPERINTERFACES, String.join(", ", interfaceInfo.superInterfaceTypeList));
    node.setProperty(JavaCodeExtractor.INTERFACE_ACCESS, interfaceInfo.visibility);
    node.setProperty(JavaCodeExtractor.INTERFACE_COMMENT, interfaceInfo.comment);
    node.setProperty(JavaCodeExtractor.INTERFACE_CONTENT, interfaceInfo.content);
    node.setProperty(JavaCodeExtractor.SIGNATURE, interfaceInfo.fullName);
}
 
Example 9
Source File: JiraUtils.java    From SnowGraph with Apache License 2.0 5 votes vote down vote up
public static void createIssueUserNode(IssueUserInfo issueUserInfo, Node node) {
    node.addLabel(Label.label(JiraExtractor.ISSUEUSER));
    node.setProperty(JiraExtractor.ISSUEUSER_NAME, issueUserInfo.getName());
    node.setProperty(JiraExtractor.ISSUEUSER_EMAIL_ADDRESS, issueUserInfo.getName());
    node.setProperty(JiraExtractor.ISSUEUSER_DISPLAY_NAME, issueUserInfo.getName());
    node.setProperty(JiraExtractor.ISSUEUSER_ACTIVE, issueUserInfo.getName());
}
 
Example 10
Source File: BugzillaUtils.java    From SnowGraph with Apache License 2.0 5 votes vote down vote up
public static void creatIssueCommentNode(BugCommentInfo commentInfo, Node node) {
    node.addLabel(Label.label(BugzillaExtractor.ISSUECOMMENT));
    node.setProperty(BugzillaExtractor.COMMENT_ID, commentInfo.getCommentId());
    node.setProperty(BugzillaExtractor.COMMENT_WHO, commentInfo.getWho());
    node.setProperty(BugzillaExtractor.COMMENT_NAME, commentInfo.getWhoName());
    node.setProperty(BugzillaExtractor.COMMENT_BUGWHEN, commentInfo.getBugWhen());
    node.setProperty(BugzillaExtractor.COMMENT_THETEXT, commentInfo.getThetext());
}
 
Example 11
Source File: DL4JMLModel.java    From neo4j-ml-procedures with Apache License 2.0 5 votes vote down vote up
@Override
    List<Node> show() {
        if ( state != State.ready ) throw new IllegalStateException("Model not trained yet");
        List<Node> result = new ArrayList<>();
        int layerCount = model.getnLayers();
        for (Layer layer : model.getLayers()) {
            Node node = node("Layer",
                    "type", layer.type().name(), "index", layer.getIndex(),
                    "pretrainLayer", layer.isPretrainLayer(), "miniBatchSize", layer.getInputMiniBatchSize(),
                    "numParams", layer.numParams());
            if (layer instanceof DenseLayer) {
                DenseLayer dl = (DenseLayer) layer;
                node.addLabel(Label.label("DenseLayer"));
                node.setProperty("activation",dl.getActivationFn().toString()); // todo parameters
                node.setProperty("biasInit",dl.getBiasInit());
                node.setProperty("biasLearningRate",dl.getBiasLearningRate());
                node.setProperty("l1",dl.getL1());
                node.setProperty("l1Bias",dl.getL1Bias());
                node.setProperty("l2",dl.getL2());
                node.setProperty("l2Bias",dl.getL2Bias());
                node.setProperty("distribution",dl.getDist().toString());
                node.setProperty("in",dl.getNIn());
                node.setProperty("out",dl.getNOut());
            }
            result.add(node);
//            layer.preOutput(allOne, Layer.TrainingMode.TEST);
//            layer.p(allOne, Layer.TrainingMode.TEST);
//            layer.activate(allOne, Layer.TrainingMode.TEST);
        }
        return result;
    }
 
Example 12
Source File: GraphNodeUtil.java    From SnowGraph with Apache License 2.0 5 votes vote down vote up
public static void createDocumentNode(WordDocumentInfo doc, Node node) {
    node.addLabel(Label.label(WordKnowledgeExtractor.DOCX_FILE));
    if(doc.getName() != null) node.setProperty(WordKnowledgeExtractor.DOCX_NAME, doc.getName());
    else node.setProperty(WordKnowledgeExtractor.DOCX_NAME, "");
    if(doc.getAbsolutePath() != null) node.setProperty(WordKnowledgeExtractor.ABSOLUTE_PATH, doc.getAbsolutePath());
    else node.setProperty(WordKnowledgeExtractor.ABSOLUTE_PATH, "");
    if(doc.getUsageType() != null) node.setProperty(WordKnowledgeExtractor.DOC_USEGE_TYPE, doc.getUsageType());
    else node.setProperty(WordKnowledgeExtractor.DOC_USEGE_TYPE, "");
    if(doc.getProjectName() != null) node.setProperty(WordKnowledgeExtractor.DOCX_PROJECT_NAME, doc.getProjectName());
    else node.setProperty(WordKnowledgeExtractor.DOCX_PROJECT_NAME, "");
}
 
Example 13
Source File: CliqueTest.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Test
public void anonymousLeader() {
  Node a = createNode("http://x.org/a");
  Node b = createNode("http://x.org/b");
  Node c = createNode("http://x.org/c");
  a.addLabel(OwlLabels.OWL_ANONYMOUS);
  b.addLabel(OwlLabels.OWL_ANONYMOUS);
  List<Node> cliqueNode = Arrays.asList(a, b, c);
  assertThat(clique.electCliqueLeader(cliqueNode, new ArrayList<String>()).getId(), is(c.getId()));
  assertThat(clique.electCliqueLeader(Arrays.asList(a, b), new ArrayList<String>()).getId(), is(a.getId()));
}
 
Example 14
Source File: JiraUtils.java    From SnowGraph with Apache License 2.0 5 votes vote down vote up
public static void createPatchNode(PatchInfo patchInfo, Node node) {
    node.addLabel(Label.label(JiraExtractor.PATCH));
    node.setProperty(JiraExtractor.PATCH_ISSUE_ID, patchInfo.getIssueId());
    node.setProperty(JiraExtractor.PATCH_ID, patchInfo.getPatchId());
    node.setProperty(JiraExtractor.PATCH_NAME, patchInfo.getPatchName());
    node.setProperty(JiraExtractor.PATCH_CONTENT, patchInfo.getContent());
    node.setProperty(JiraExtractor.PATCH_CREATOR_NAME, patchInfo.getCreatorName());
    node.setProperty(JiraExtractor.PATCH_CREATED_DATE, patchInfo.getCreatedDate());
}
 
Example 15
Source File: GraphNodeUtil.java    From SnowGraph with Apache License 2.0 5 votes vote down vote up
public static void createTableNode(TableInfo table, Node node) {
    node.addLabel(Label.label(WordKnowledgeExtractor.DOCX_TABLE));
    if(table.getTableCaption() != null) node.setProperty(WordKnowledgeExtractor.TABLE_CAPTION, table.getTableCaption());
    else node.setProperty(WordKnowledgeExtractor.TABLE_CAPTION, "");
    if(table.getTableNumber() != null) node.setProperty(WordKnowledgeExtractor.TABLE_NUMBER, table.getTableNumber());
    else node.setProperty(WordKnowledgeExtractor.TABLE_NUMBER, "");
    node.setProperty(WordKnowledgeExtractor.TABLE_COLUMN_NUM, table.getColumnSize());
    node.setProperty(WordKnowledgeExtractor.TABLE_ROW_NUM, table.getRowSize());
}
 
Example 16
Source File: CategoryLabeler.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Override
public Boolean call() throws Exception {
  Label label = Label.label(category);
  try (Transaction tx = graphDb.beginTx()) {
    for (Long id : ids) {
      Node node = graphDb.getNodeById(id);
      GraphUtil.addProperty(node, Concept.CATEGORY, category);
      node.addLabel(label);
    }
    tx.success();
    tx.close();
  }
  return true;
}
 
Example 17
Source File: WriterTest.java    From neo4j-mazerunner with Apache License 2.0 4 votes vote down vote up
private void createSampleGraph(GraphDatabaseService db) {

        List<Node> nodes = new ArrayList<>();

        int max = 200;
        Transaction tx = db.beginTx();
        Node partitionNode = db.createNode();
        partitionNode.addLabel(DynamicLabel.label("Category"));
        tx.success();
        tx.close();
        int count = 0;
        int partitionBlockCount = 50;

        tx = db.beginTx();
        // Create nodes
        for (int i = 0; i < max; i++) {

            nodes.add(db.createNode());
            nodes.get(i).addLabel(DynamicLabel.label("Node"));
            partitionNode.createRelationshipTo(nodes.get(i), withName("HAS_CATEGORY"));
            count++;
            if(count >= partitionBlockCount && i != max - 1) {

                count = 0;
                partitionNode = db.createNode();
                partitionNode.addLabel(DynamicLabel.label("Category"));

                tx.success();
                tx.close();
                tx = db.beginTx();

                System.out.println(i);
            }
        }

        tx.success();
        tx.close();

        tx = db.beginTx();
        // Create PageRank test graph
        for (int i = 0; i < (max / 2) - 1; i++) {
            nodes.get(i).createRelationshipTo(nodes.get(i + (max / 2)), withName("CONNECTED_TO"));
            nodes.get(i + (max / 2)).createRelationshipTo(nodes.get(i + 1), withName("CONNECTED_TO"));
            if(count >= partitionBlockCount / 2 && i != max - 1) {
                tx.success();
                tx.close();
                tx = db.beginTx();

                System.out.println("B: " + i);
            }
            if(i == (max / 2) - 2) {
                nodes.get((i + 1) + (max / 2)).createRelationshipTo(nodes.get(0), withName("CONNECTED_TO"));
                nodes.get(i + 1).createRelationshipTo(nodes.get((max / 2)), withName("CONNECTED_TO"));
            }
        }

        tx.success();
        tx.close();
    }
 
Example 18
Source File: UniqueNodeFactory.java    From neo4jena with Apache License 2.0 4 votes vote down vote up
/**
 * Initializes the node.
 */
@Override
protected void initialize(Node created, Map<String, Object> properties) {
	created.addLabel(DynamicLabel.label(NeoGraph.LABEL_URI));
	created.setProperty(NeoGraph.PROPERTY_URI, properties.get(NeoGraph.PROPERTY_URI));
}
 
Example 19
Source File: Clique.java    From SciGraph with Apache License 2.0 4 votes vote down vote up
private void markAsCliqueLeader(Node n) {
  if (!n.hasLabel(CLIQUE_LEADER_LABEL)) {
    n.addLabel(CLIQUE_LEADER_LABEL);
  }
}
 
Example 20
Source File: WriterTest.java    From neo4j-mazerunner with Apache License 2.0 2 votes vote down vote up
@Test
public void testParallelUpdate() throws Exception {

    GraphDatabaseService db = setUpDb();

    Transaction tx = db.beginTx();


    // Use test configurations
    ConfigurationLoader.testPropertyAccess = true;

    Node nodePartition = db.createNode();
    nodePartition.addLabel(DynamicLabel.label("Category"));

    PartitionDescription partitionDescription = new PartitionDescription(nodePartition.getId(), "Category");

    // Create sample PageRank result
    String nodeList = "";

    for(int i = 0; i < 100; i++)
    {
        db.createNode();
        nodeList += i + " .001\n";
    }

    tx.success();
    tx.close();

    // Create test path
    String path = ConfigurationLoader.getInstance().getHadoopHdfsUri() + "/test/propertyNodeList.txt";

    writeListFile(path, nodeList);

    ProcessorMessage processorMessage = new ProcessorMessage(path, "pagerank", ProcessorMode.Partitioned);
    processorMessage.setPartitionDescription(partitionDescription);

    BufferedReader br = FileUtil.readGraphAdjacencyList(processorMessage);
    BufferedReader br2 = FileUtil.readGraphAdjacencyList(processorMessage);

    // Test parallel update
    PartitionedAnalysis.updatePartition(processorMessage, br, db);
    PartitionedAnalysis.updatePartition(processorMessage, br2, db);
}