Java 类org.neo4j.graphdb.Label 实例源码

项目:neo4j-talend-component    文件:Neo4jBatchInserterNode.java   
protected Label[] computeLabels(Object incoming) throws IllegalAccessException {
    Label[] labels = new Label[0];

    if (StringUtils.isNotEmpty(this.labelsField)) {

        String labelList = (String) this.getObjectProperty(incoming, this.labelsField);

        if (StringUtils.isNotEmpty(labelList)) {
            String[] labelTab = labelList.split(";");
            labels = new Label[labelTab.length];
            for (int i = 0; i < labelTab.length; i++) {
                labels[i] = DynamicLabel.label(labelTab[i]);
            }
        }
    }

    return labels;
}
项目:SnowGraph    文件:ReferenceExtractor.java   
public void run(GraphDatabaseService db) {
    this.db = db;
    codeIndexes = new CodeIndexes(db);
    try (Transaction tx=db.beginTx()){
        for (Node node:db.getAllNodes()){
            if (!node.hasProperty(TextExtractor.IS_TEXT)||!(boolean)node.getProperty(TextExtractor.IS_TEXT))
                continue;
            if (node.hasLabel(Label.label(JavaCodeExtractor.CLASS)))
                continue;
            if (node.hasLabel(Label.label(JavaCodeExtractor.METHOD)))
                continue;
            if (node.hasLabel(Label.label(JavaCodeExtractor.INTERFACE)))
                continue;
            if (node.hasLabel(Label.label(JavaCodeExtractor.FIELD)))
                continue;
            textNodes.add(node);
        }
        fromHtmlToCodeElement();
        fromTextToJira();
        fromDiffToCodeElement();
        tx.success();
    }
}
项目:SnowGraph    文件:ReferenceExtractor.java   
private void fromTextToJira(){
    Map<String, Node> jiraMap=new HashMap<>();
    try (Transaction tx = db.beginTx()) {
        for (Node node:db.getAllNodes()){
            if (node.hasLabel(Label.label(JiraExtractor.ISSUE))){
                String name=(String) node.getProperty(JiraExtractor.ISSUE_NAME);
                jiraMap.put(name, node);
            }
        }
        tx.success();
    }
    try (Transaction tx = db.beginTx()) {
        for (Node srcNode : textNodes) {
            String content = text(srcNode);
            Set<String> tokenSet=new HashSet<>();
            for (String e:content.split("[^A-Za-z0-9\\-_]+"))
                tokenSet.add(e);
            for (String jiraName:jiraMap.keySet()){
                if (tokenSet.contains(jiraName))
                    srcNode.createRelationshipTo(jiraMap.get(jiraName), RelationshipType.withName(REFERENCE));
            }
        }
        tx.success();
    }
}
项目:SnowGraph    文件:JiraUtils.java   
public static void createIssueNode(IssueInfo issueInfo, Node node) {
    node.addLabel(Label.label(JiraExtractor.ISSUE));
    node.setProperty(JiraExtractor.ISSUE_ID, issueInfo.getIssueId());
    node.setProperty(JiraExtractor.ISSUE_NAME, issueInfo.getIssueName());
    node.setProperty(JiraExtractor.ISSUE_SUMMARY, issueInfo.getSummary());
    node.setProperty(JiraExtractor.ISSUE_TYPE, issueInfo.getType());
    node.setProperty(JiraExtractor.ISSUE_STATUS, issueInfo.getStatus());
    node.setProperty(JiraExtractor.ISSUE_PRIORITY, issueInfo.getPriority());
    node.setProperty(JiraExtractor.ISSUE_RESOLUTION, issueInfo.getResolution());
    node.setProperty(JiraExtractor.ISSUE_VERSIONS, issueInfo.getVersions());
    node.setProperty(JiraExtractor.ISSUE_FIX_VERSIONS, issueInfo.getFixVersions());
    node.setProperty(JiraExtractor.ISSUE_COMPONENTS, issueInfo.getComponents());
    node.setProperty(JiraExtractor.ISSUE_LABELS, issueInfo.getLabels());
    node.setProperty(JiraExtractor.ISSUE_DESCRIPTION, issueInfo.getDescription());
    node.setProperty(JiraExtractor.ISSUE_CREATOR_NAME, issueInfo.getCrearorName());
    node.setProperty(JiraExtractor.ISSUE_ASSIGNEE_NAME, issueInfo.getAssigneeName());
    node.setProperty(JiraExtractor.ISSUE_REPORTER_NAME, issueInfo.getReporterName());
    node.setProperty(JiraExtractor.ISSUE_CREATED_DATE, issueInfo.getCreatedDate());
    node.setProperty(JiraExtractor.ISSUE_UPDATED_DATE, issueInfo.getUpdatedDate());
    node.setProperty(JiraExtractor.ISSUE_RESOLUTION_DATE, issueInfo.getResolutionDate());
}
项目:SnowGraph    文件:MboxHandler.java   
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));

}
项目:SnowGraph    文件:BugzillaUtils.java   
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());
}
项目:SnowGraph    文件:GraphNodeUtil.java   
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, "");
}
项目:SnowGraph    文件:QaUserInfo.java   
public QaUserInfo(Node node, int id, int reputation, String creationDate, String displayName, String lastAccessDate, int views, int upVotes, int downVotes) {
    this.node = node;
    this.userId = id;
    this.displayName = displayName;

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

    node.setProperty(StackOverflowExtractor.USER_ID, id);
    node.setProperty(StackOverflowExtractor.USER_REPUTATION, reputation);
    node.setProperty(StackOverflowExtractor.USER_CREATION_DATE, creationDate);
    node.setProperty(StackOverflowExtractor.USER_DISPLAY_NAME, displayName);
    node.setProperty(StackOverflowExtractor.USER_LAST_ACCESS_dATE, lastAccessDate);
    node.setProperty(StackOverflowExtractor.USER_VIEWS, views);
    node.setProperty(StackOverflowExtractor.USER_UP_VOTES, upVotes);
    node.setProperty(StackOverflowExtractor.USER_DOWN_VOTES, downVotes);
}
项目:SnowGraph    文件:AnswerInfo.java   
public AnswerInfo(Node node, int id, int parentId, String creationDate, int score, String body, int ownerUserId) {
    this.node = node;
    this.answerId = id;
    this.parentQuestionId = parentId;
    this.ownerUserId = ownerUserId;

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

    node.setProperty(StackOverflowExtractor.ANSWER_ID, id);
    node.setProperty(StackOverflowExtractor.ANSWER_PARENT_QUESTION_ID, parentId);
    node.setProperty(StackOverflowExtractor.ANSWER_CREATION_DATE, creationDate);
    node.setProperty(StackOverflowExtractor.ANSWER_SCORE, score);
    node.setProperty(StackOverflowExtractor.ANSWER_BODY, body);
    node.setProperty(StackOverflowExtractor.ANSWER_OWNER_USER_ID, ownerUserId);
    node.setProperty(StackOverflowExtractor.ANSWER_ACCEPTED, false);

}
项目:SnowGraph    文件:QuestionInfo.java   
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);

}
项目:SnowGraph    文件:QaCommentInfo.java   
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);

}
项目:SnowGraph    文件:JavaCodeUtils.java   
public static void createMethodNode(MethodInfo methodInfo, Node node) {
    node.addLabel(Label.label(JavaCodeExtractor.METHOD));
    node.setProperty(JavaCodeExtractor.METHOD_NAME, methodInfo.name);
    node.setProperty(JavaCodeExtractor.METHOD_RETURN, methodInfo.returnString);
    node.setProperty(JavaCodeExtractor.METHOD_ACCESS, methodInfo.visibility);
    node.setProperty(JavaCodeExtractor.METHOD_IS_CONSTRUCTOR, methodInfo.isConstruct);
    node.setProperty(JavaCodeExtractor.METHOD_IS_ABSTRACT, methodInfo.isAbstract);
    node.setProperty(JavaCodeExtractor.METHOD_IS_FINAL, methodInfo.isFinal);
    node.setProperty(JavaCodeExtractor.METHOD_IS_STATIC, methodInfo.isStatic);
    node.setProperty(JavaCodeExtractor.METHOD_IS_SYNCHRONIZED, methodInfo.isSynchronized);
    node.setProperty(JavaCodeExtractor.METHOD_CONTENT, methodInfo.content);
    node.setProperty(JavaCodeExtractor.METHOD_COMMENT, methodInfo.comment);
    node.setProperty(JavaCodeExtractor.METHOD_BELONGTO, methodInfo.belongTo);
    node.setProperty(JavaCodeExtractor.METHOD_PARAMS, methodInfo.paramString);
    node.setProperty(JavaCodeExtractor.METHOD_THROWS, String.join(", ", methodInfo.throwSet));
    node.setProperty(JavaCodeExtractor.SIGNATURE, methodInfo.belongTo+"."+methodInfo.name+"("+methodInfo.paramString+")");
}
项目:codemodel-rifle    文件:SimpleWalker.java   
@Override
public <R, E extends Throwable> R accept(Visitor<R, E> visitor) throws E {
    for (Node node : dbServices.getAllNodes()) {
        if (node.hasLabel(Label.label("CompilationUnit"))) {
            continue;
        }
        if (node.hasLabel(Label.label("SourceSpan"))) {
            continue;
        }
        if (node.hasLabel(Label.label("SourceLocation"))) {
            continue;
        }

        visitor.visitNode(node);
        for (Relationship edge : node.getRelationships(Direction.OUTGOING)) {
            if (edge.isType(RelationshipType.withName("location"))) {
                continue;
            }
            visitor.visitRelationship(edge);
        }
    }
    return visitor.done();
}
项目:doc2graph    文件:JsonHelperConfiguration.java   
/**
 * Get current configuration manager
 * @return
 */
public static DocumentGrapherExecutionContext newContext(GraphDatabaseService db, Log log)
{

    if(instance == null)
    {
        Node configurationNode = db.findNode(Label.label("JSON_CONFIG"), "configuration", "byNode");
        if(configurationNode == null)
        {
            log.info("Load default configuration: "+JsonHelperConfigurationDefault.class);
            instance = new JsonHelperConfigurationDefault();                
        }else
        {
            log.info("Load configuration from node: "+JsonHelperConfigurationByNode.class);
            instance = new JsonHelperConfigurationByNode(configurationNode);    
        }
    }

    return instance.buildContext(db, log);
}
项目:doc2graph    文件:DocumentGrapherRecursive.java   
/**
 * Search into database if exists a node with documentId
 * @param label 
 * @param documentId
 * @return
 */
private Node findNodeIntoGraphDb(Label label, DocumentId documentId) {
    Node node = null;

    //check if node already exists
    String query = "MATCH (n:"+label.name()+" {"+documentId.toCypherFilter()+"}) RETURN n";
    if(log.isDebugEnabled())
    {
        log.debug(query);
    }

    Result result = db.execute(query);
    while (result.hasNext()) {
        Map<String, Object> row = result.next();
        node = (Node) row.get("n");
        if(log.isDebugEnabled())
        {
            log.debug("Found: "+node);
        }
    }
    return node;
}
项目:doc2graph    文件:JsonHelperConfigurationTest.java   
/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    Map<String, Object> allProps = new HashMap<>();
    allProps.put("configuration", "byNode");
    allProps.put("root_node_key_property", "_root_");
    allProps.put("document_id_builder", "org.neo4j.helpers.json.document.impl.DocumentIdBuilderId");
    allProps.put("document_relation_builder", "org.neo4j.helpers.json.document.impl.DocumentRelationBuilderByKey");
    allProps.put("document_label_builder", "org.neo4j.helpers.json.document.impl.DocumentLabelBuilderById");

    JsonHelperConfiguration.reset();
    expect(confNode.getAllProperties()).andStubReturn(allProps);
    /*
    expect(confNode.getProperty("configuration")).andStubReturn("byNode");
    expect(confNode.getProperty("root_node_key_property")).andStubReturn("_root_");
    expect(confNode.getProperty("document_id_builder")).andStubReturn("org.neo4j.helpers.json.document.impl.DocumentIdBuilderId");
    expect(confNode.getProperty("document_relation_builder")).andStubReturn("org.neo4j.helpers.json.document.impl.DocumentRelationBuilderByKey");
    expect(confNode.getProperty("document_label_builder")).andStubReturn("org.neo4j.helpers.json.document.impl.DocumentLabelBuilderById");      
    */
    expect(db.findNode(Label.label("JSON_CONFIG"), "configuration", "byNode")).andReturn(confNode);
    replay(db,log, confNode);
}
项目:NeoDD    文件:Problem.java   
public final Node add(Map<String, Object> properties, String... types) {
    if (null == properties)
        throw new IllegalArgumentException("Illegal 'properties' argument in Problem.add(Map<String, Object>, String...): " + properties);
    if (null == types)
        throw new IllegalArgumentException("Illegal 'types' argument in Problem.add(Map<String, Object>, String...): " + types);
    Node result = null;
    try (Transaction tx = graph.beginTx()) {
        int i = 0;
        Label[] labels = new Label[types.length];
        for (String type : types) {
            labels[i++] = DynamicLabel.label(type);
        }
        result = graph.createNode(labels);
        for (String property : properties.keySet())
            result.setProperty(property, properties.get(property));
        tx.success();
    }
    return result;
}
项目:neo4j-lucene5-index    文件:IndexConstraintsTest.java   
private IndexDefinition getIndex( Label label, String propertyKey )
{
    try ( Transaction tx = graphDb.beginTx() )
    {
        IndexDefinition found = null;
        for ( IndexDefinition index : graphDb.schema().getIndexes( label ) )
        {
            if ( propertyKey.equals( single( index.getPropertyKeys() ) ) )
            {
                assertNull( "Found multiple indexes.", found );
                found = index;
            }
        }
        tx.success();
        return found;
    }
}
项目:neo4j-lucene5-index    文件:IndexConstraintsTest.java   
private ConstraintDefinition getConstraint( Label label, String propertyKey )
{
    try ( Transaction tx = graphDb.beginTx() )
    {
        ConstraintDefinition found = null;
        for ( ConstraintDefinition constraint : graphDb.schema().getConstraints( label ) )
        {
            if ( propertyKey.equals( single( constraint.getPropertyKeys() ) ) )
            {
                assertNull( "Found multiple constraints.", found );
                found = constraint;
            }
        }
        tx.success();
        return found;
    }
}
项目:neo4j-lucene5-index    文件:UniqueIndexApplicationIT.java   
private Function<GraphDatabaseService, List<Long>> listNodeIdsFromIndexLookup(
        final Label label, final String propertyKey, final Object value )
{
    return new Function<GraphDatabaseService, List<Long>>()
    {
        @Override
        public List<Long> apply( GraphDatabaseService graphDb )
        {
            ArrayList<Long> ids = new ArrayList<>();
            for ( Node node : loop( graphDb.findNodes( label, propertyKey, value ) ) )
            {
                ids.add( node.getId() );
            }
            return ids;
        }
    };
}
项目:neo4j-lucene5-index    文件:ConstraintIndexConcurrencyTest.java   
private static Function<GraphDatabaseService,Void> createNode(
        final Label label, final String key, final Object value )
{
    return new Function<GraphDatabaseService,Void>()
    {
        @Override
        public Void apply( GraphDatabaseService graphDb )
        {
            try ( Transaction tx = graphDb.beginTx() )
            {
                graphDb.createNode( label ).setProperty( key, value );
                tx.success();
            }
            return null;
        }
    };
}
项目:trainbenchmark    文件:Neo4jUtil.java   
public static Iterable<Node> getAdjacentNodes(final Node sourceNode, final RelationshipType relationshipType, final Direction direction, final Label targetNodeLabel) {
    final Collection<Node> nodes = new ArrayList<>();

    final Iterable<Relationship> relationships = sourceNode.getRelationships(relationshipType, direction);
    for (final Relationship relationship : relationships) {
        final Node candidate;
        switch (direction) {
        case INCOMING:
            candidate = relationship.getStartNode();
            break;
        case OUTGOING:
            candidate = relationship.getEndNode();          
            break;
        default:
            throw new UnsupportedOperationException("Direction: " + direction + " not supported.");
        }
        if (!candidate.hasLabel(targetNodeLabel)) {
            continue;
        }
        nodes.add(candidate);
    }
    return nodes;
}
项目:knowledge-extraction    文件:Neo4JDb.java   
private Node getNode(Label label, String key, Object value) {
    Node node = null;
    try (Transaction tx = graphDb.beginTx()) {
        ResourceIterator<Node> nodes = null;
        if (label != null){
            nodes = graphDb.findNodesByLabelAndProperty(
                label, key, value).iterator();
        }
        else {
            String validValue = StringEscapeUtils.escapeJavaScript((String) value);
            ExecutionEngine engine = new ExecutionEngine(graphDb);
            nodes = engine.execute(
                    "START n=node(*)"
                    + " WHERE n." + key + "=\"" + validValue + "\""
                    + " RETURN n").columnAs("n");

        }
        if (nodes.hasNext()) {
            node = nodes.next();
        }
        nodes.close();
    }
    return node;
}
项目:neo4jena    文件:UniqueRelationshipFactory.java   
/**
 * Finds relationship of given type between subject and object nodes.
 * 
 * @return Relationship if exists or null.
 */
public Relationship get(Node subject, RelationshipType type, Node object) {
    try {
        // FIXME Use relationship index instead of iterating over all relationships
        Iterable<Relationship> relations = subject.getRelationships(Direction.OUTGOING, type);
        for(Relationship relation: relations) {
            org.neo4j.graphdb.Node target = relation.getEndNode();
            // Match object with target node in the existing triple
            Iterable<Label> labels = object.getLabels();
            for(Label label:labels) {
                if(label.name().equals(NeoGraph.LABEL_LITERAL)) {
                    // Match literal value of object and target in existing triple
                    if(object.getProperty(NeoGraph.PROPERTY_VALUE).equals(target.getProperty(NeoGraph.PROPERTY_VALUE)))
                        return relation;
                    else return null;
                }
            }
            // Now match URI of object and target in existing triple
            // FIXME Blank Nodes?
            if(object.getProperty(NeoGraph.PROPERTY_URI).equals(target.getProperty(NeoGraph.PROPERTY_URI)))
                return relation;
        }
    } catch(RuntimeException exception) { }
    return null;
}
项目:maven-embedded-neo4j-archetype    文件:Neo4jEmbeddedExample.java   
public String helloWorldTraversal() {
    StringBuilder values = new StringBuilder();
    try (Transaction tx = graphDatabaseService.beginTx()) {
        Node startNode = graphDatabaseService.findNode(Label.label("Word"), "value", "Hello");
        for (Node node : graphDatabaseService.traversalDescription()
                .depthFirst()
                .expand(forTypeAndDirection(withName("IS_FOLLOWED_BY"), Direction.OUTGOING))
                .evaluator(toDepth(2))
                .traverse(startNode)
                .nodes()) {

            values.append(String.valueOf(node.getProperty("value")));
            values.append(" ");
        }
        tx.success();
    }
    return values.substring(0, values.length() - 1);
}
项目:SciGraph    文件:Neo4jModule.java   
public static void setupSchemaIndexes(GraphDatabaseService graphDb, Neo4jConfiguration config) {
  Map<String, Set<String>> schemaIndexes = config.getSchemaIndexes();
  for (Map.Entry<String, Set<String>> entry : schemaIndexes.entrySet()) {
    Label label = Label.label(entry.getKey());
    for (String property : entry.getValue()) {
      try (Transaction tx = graphDb.beginTx()) {
        Schema schema = graphDb.schema();
        IndexDefinition indexDefinition = schema.indexFor(label).on(property).create();
        tx.success();
        tx.close();

        Transaction tx2 = graphDb.beginTx();
        schema.awaitIndexOnline(indexDefinition, 2, TimeUnit.MINUTES);
        tx2.success();
        tx2.close();
      }
    }
  }
}
项目:SciGraph    文件:Clique.java   
@Inject
public Clique(GraphDatabaseService graphDb, CliqueConfiguration cliqueConfiguration) {
  this.graphDb = graphDb;
  this.prefixLeaderPriority = cliqueConfiguration.getLeaderPriority();
  this.leaderAnnotationProperty = cliqueConfiguration.getLeaderAnnotation();

  Set<Label> tmpLabels = new HashSet<Label>();
  for (String l : cliqueConfiguration.getLeaderForbiddenLabels()) {
    tmpLabels.add(Label.label(l));
  }
  this.forbiddenLabels = tmpLabels;

  Set<RelationshipType> tmpRelationships = new HashSet<RelationshipType>();
  for (String r : cliqueConfiguration.getRelationships()) {
    tmpRelationships.add(RelationshipType.withName(r));
  }
  this.relationships = tmpRelationships;

  this.batchCommitSize = cliqueConfiguration.getBatchCommitSize();
}
项目:SciGraph    文件:GraphApi.java   
public Optional<Node> getNode(String id, Optional<String> lblHint) {
  String iriResolved = curieUtil.getIri(id).orElse(id);
  Optional<Node> node = Optional.empty();
  if (lblHint.isPresent()) {
    Label hintLabel = Label.label(lblHint.get());
    Node hit = graphDb.findNode(hintLabel, NodeProperties.IRI, iriResolved);
    if (hit != null) {
      node = Optional.of(hit);
    }
  } else {
    String startQuery =
        "MATCH (n {" + NodeProperties.IRI + ": \"" + iriResolved + "\"}) RETURN n";
    Result res = cypherUtil.execute(startQuery);
    if (res.hasNext()) {
      node = Optional.of((Node) res.next().get("n"));
    }
  }

  return node;
}
项目:dswarm-graph-neo4j    文件:Neo4jDeltaGDMHandler.java   
private void addLabel(final Node node, final String labelString) {

        final Label label = DynamicLabel.label(labelString);
        boolean hit = false;
        final Iterable<Label> labels = node.getLabels();

        for (final Label lbl : labels) {

            if (label.equals(lbl)) {

                hit = true;
                break;
            }
        }

        if (!hit) {

            node.addLabel(label);
            addedLabels++;
        }
    }
项目:dswarm-graph-neo4j    文件:BasicNeo4jProcessor.java   
public void addLabel(final Node node, final String labelString) {

        final Label label = getLabel(labelString);
        boolean hit = false;
        final Iterable<Label> labels = node.getLabels();

        for (final Label lbl : labels) {

            if (label.equals(lbl)) {

                hit = true;
                break;
            }
        }

        if (!hit) {

            node.addLabel(label);
            addedLabels++;
        }
    }
项目:dgMaster-trunk    文件:EntityEventNodeNeo4j.java   
/**
 * used when creating nodes in batch mode
 * 
 * @param id
 * @param name
 * @param columnNames
 * @param values
 * @return
 * @throws IOException
 */
private long createVertexBatchMode(double id, String name, List<String> columnNames, List<String> values) throws IOException {
    Label entityLabel = DynamicLabel.label(name);
    //getCurrentInserter().createDeferredSchemaIndex(entityLabel).on(_ID_PROPERTY).create();

    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(_ID_PROPERTY, id);

    // fill out the properties in the columns
    for (int i = 0; i < columnNames.size(); i++) {
        String value = EMPTY_STRING;
        if (values != null && values.size() > i) {
            value = values.get(i);
        }
        properties.put(columnNames.get(i), value);
    }

    return getCurrentInserter().createNode(properties, entityLabel);
}
项目:PhenoImageShare    文件:Neo4jAccessUtils.java   
private Node createNode(String id, Label label) 
throws PhisSubmissionException{

    Node myNode;
    System.out.println("Label + " + label);
    if (id == null || id.equals("")){
        throw getEmptyIdException();
    } 
    else if (existsId(id, label)){
        throw getIdAlreadyExists(id);
    }
    try ( Transaction tx = db.beginTx() )
       {
           myNode = db.createNode(label);
           myNode.setProperty( AnnotationProperties.ID.name(), id );
           tx.success();
           tx.close();
       }   

    return myNode;

}
项目:PhenoImageShare    文件:Neo4jAccessUtils.java   
public Node getOrCreateNode(String id, String name, Label label, boolean overWrite) 
throws PhisSubmissionException{

    Node res ;

    if ( existsId(id, label) ){
        if (overWrite){
            deleteNodeWithRelations(id);
            res = createNode(id, label);
        } else {
            res = getNodeById(id);
        }
    } else {
        res = createNode(id, label);
    }
    res.setProperty(AnnotationProperties.ID.name(), name);

    return res;

}
项目:csvtreeloader    文件:CSVTreeBuilder.java   
private void dumpTree(PrintStream out, Node node, TreeNodeBuilder builder, int level) {
    try (Transaction tx = db.beginTx()) {
        String prefix = "    ";
        for (int i = 0; i < level; i++) {
            prefix += "    ";
        }
        if (builder.parentBuilder != null) {
            prefix += "-[:" + builder.parentBuilder.childRel.toString() + "]->";
        }
        Iterator<Label> labelIterator = node.getLabels().iterator();
        String label = labelIterator.hasNext() ? labelIterator.next().name() : "Node";
        out.println(prefix + label + "[" + node.getId() + "]" + ": "
                + node.getProperty(builder.column.property));
        for (Relationship rel : node
                .getRelationships(Direction.OUTGOING, builder.childRel)) {
            dumpTree(out, rel.getEndNode(), builder.childBuilder, level + 1);
        }
        tx.success();
    }
}
项目:obelix    文件:ObelixBatchImport.java   
private static long getOrCreateUserNodeID(final String userid,
                                          final Map<String, Long> usersNodesMap,
                                          final BatchInserterIndex usersIndex,
                                          final BatchInserter inserter,
                                          final Label label) {

    long userNodeID;

    if (usersNodesMap.containsKey(userid)) {
        userNodeID = usersNodesMap.get(userid);
    } else {
        userNodeID = inserter.createNode(MapUtil.map("node_id", userid), label);
        usersNodesMap.put(userid, userNodeID);
        usersIndex.add(userNodeID, MapUtil.map("node_id", userid));
    }

    return userNodeID;

}
项目:obelix    文件:ObelixBatchImport.java   
private static long getOrCreateItemNodeID(final String itemid,
                                          final Map<String, Long> itemsNodesMap,
                                          final BatchInserterIndex itemsIndex,
                                          final BatchInserter inserter,
                                          final Label label) {

    long itemNodeID;

    if (itemsNodesMap.containsKey(itemid)) {
        itemNodeID = itemsNodesMap.get(itemid);
    } else {
        itemNodeID = inserter.createNode(MapUtil.map("node_id", itemid), label);
        itemsNodesMap.put(itemid, itemNodeID);
        itemsIndex.add(itemNodeID, MapUtil.map("node_id", itemid));
    }

    return itemNodeID;

}
项目:obelix    文件:NeoHelpers.java   
public static List<String> getAllNodes(final GraphDatabaseService graphDb,
                                       final String labelName) {

    List<String> nodeIds = new ArrayList<>();
    Label label = DynamicLabel.label(labelName);
    ResourceIterable<Node> nodes;

    try (Transaction tx = graphDb.beginTx()) {
        nodes = GlobalGraphOperations.at(graphDb).getAllNodesWithLabel(label);

        for (Node node : nodes) {
            try {
                nodeIds.add(node.getProperty("node_id").toString());
            } catch (Exception e) {
                LOGGER.warn("Can't find a given node... skipping");
            }
        }

        tx.success();
    }

    return nodeIds;

}
项目:jcypher    文件:AbstractEmbeddedDBAccess.java   
private void init(Node node) {
    JsonObjectBuilder nd = Json.createObjectBuilder();
    nd.add("id", String.valueOf(node.getId()));
    JsonArrayBuilder labels = Json.createArrayBuilder();
    Iterator<Label> lblIter = node.getLabels().iterator();
    boolean hasLabels = false;
    while (lblIter.hasNext()) {
        hasLabels = true;
        Label lab = lblIter.next();
        labels.add(lab.name());
    }
    if (hasLabels)
        nd.add("labels", labels);
    JsonObjectBuilder props = Json.createObjectBuilder();
    Iterator<String> pit = node.getPropertyKeys().iterator();
    while (pit.hasNext()) {
        String pKey = pit.next();
        Object pval = node.getProperty(pKey);
        writeLiteral(pKey, pval, props);
    }
    nd.add("properties", props);
    this.nodeObject = nd;
}
项目:elasticsearch-river-neo4j    文件:Neo4jIndexer.java   
public Neo4jIndexer(SpringCypherRestGraphDatabase db,
                    ElasticOperationWorker worker,
                    IndexingStrategy indexingStrategy,
                    DeletingStategy deletingStategy,
                    String index,
                    String type,
                    List<Label> labels) {
    if (db == null) throw new IllegalStateException();
    if (worker == null) throw new IllegalStateException();
    if (indexingStrategy == null) throw new IllegalStateException();
    if (deletingStategy == null) throw new IllegalStateException();
    if (index == null) throw new IllegalStateException();
    if (type == null) throw new IllegalStateException();
    this.db = db;
    this.worker = worker;
    this.indexingStrategy = indexingStrategy;
    this.deletingStategy = deletingStategy;
    this.index = index;
    this.type = type;
    this.labels = labels;
}
项目:elasticsearch-river-neo4j    文件:Neo4jIndexer.java   
public void index() {
    version = getVersion();

    logger.debug("Awake and about to poll...");
    Iterable<Node> r = db.getAllNodes();
    for (Node node : r) {
        // If labels exists, filter nodes by label
        if(labels.size() > 0) {
            for (Label label : labels) {
                if(node.hasLabel(label)) {
                    worker.queue(new IndexOperation(indexingStrategy, index, type, node, version));
                }
            }
        } else {
            worker.queue(new IndexOperation(indexingStrategy, index, type, node, version));
        }
    }
    logger.debug("...polling completed");

    logger.debug("Deleting all nodes with version < {}", version);
    worker.queue(new ExpungeOperation(deletingStategy, index, type, version));
}