Java Code Examples for org.neo4j.graphdb.Label

The following examples show how to use org.neo4j.graphdb.Label. These examples are extracted from open source projects. 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 Project: SnowGraph   Source File: ReferenceExtractor.java    License: Apache License 2.0 6 votes vote down vote up
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();
    }
}
 
Example 2
Source Project: SnowGraph   Source File: ReferenceExtractor.java    License: Apache License 2.0 6 votes vote down vote up
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();
	}
}
 
Example 3
Source Project: SnowGraph   Source File: JiraUtils.java    License: Apache License 2.0 6 votes vote down vote up
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());
}
 
Example 4
Source Project: SnowGraph   Source File: MboxHandler.java    License: 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 5
Source Project: SnowGraph   Source File: BugzillaUtils.java    License: 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 Project: SnowGraph   Source File: GraphNodeUtil.java    License: 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 7
Source Project: SnowGraph   Source File: QaUserInfo.java    License: Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 8
Source Project: SnowGraph   Source File: AnswerInfo.java    License: Apache License 2.0 6 votes vote down vote up
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);

}
 
Example 9
Source Project: SnowGraph   Source File: QuestionInfo.java    License: 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 10
Source Project: SnowGraph   Source File: QaCommentInfo.java    License: 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 11
Source Project: SnowGraph   Source File: JavaCodeUtils.java    License: Apache License 2.0 6 votes vote down vote up
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+")");
}
 
Example 12
Source Project: trainbenchmark   Source File: Neo4jUtil.java    License: Eclipse Public License 1.0 6 votes vote down vote up
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;
}
 
Example 13
Source Project: knowledge-extraction   Source File: Neo4JDb.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 14
Source Project: neo4jena   Source File: UniqueRelationshipFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example 15
Source Project: SciGraph   Source File: Neo4jModule.java    License: Apache License 2.0 6 votes vote down vote up
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();
      }
    }
  }
}
 
Example 16
Source Project: SciGraph   Source File: Clique.java    License: Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 17
Source Project: SciGraph   Source File: GraphApi.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 18
Source Project: jcypher   Source File: AbstractEmbeddedDBAccess.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 19
Source Project: elasticsearch-river-neo4j   Source File: Neo4jIndexer.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 20
Source Project: elasticsearch-river-neo4j   Source File: Neo4jIndexer.java    License: Apache License 2.0 6 votes vote down vote up
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));
}
 
Example 21
Source Project: tutorials   Source File: Neo4jLiveTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testPersonCar() {
    graphDb.beginTx();
    Node car = graphDb.createNode(Label.label("Car"));
    car.setProperty("make", "tesla");
    car.setProperty("model", "model3");

    Node owner = graphDb.createNode(Label.label("Person"));
    owner.setProperty("firstName", "baeldung");
    owner.setProperty("lastName", "baeldung");

    owner.createRelationshipTo(car, RelationshipType.withName("owner"));

    Result result = graphDb.execute("MATCH (c:Car) <-[owner]- (p:Person) " +
            "WHERE c.make = 'tesla'" +
            "RETURN p.firstName, p.lastName");

    Map<String, Object> firstResult = result.next();
    Assert.assertEquals("baeldung", firstResult.get("p.firstName"));
}
 
Example 22
Source Project: atlas   Source File: RoadContracter.java    License: GNU General Public License v3.0 5 votes vote down vote up
public boolean contractRoad() {
    Transaction tx = db.beginTx();
    Iterator<Node> wayStartIterator = db.findNodes(Label.label("WAY_START"));
    while(wayStartIterator.hasNext()) {
        Node wayStartNode = wayStartIterator.next();

    }
    tx.success();
    tx.close();
    return true;
}
 
Example 23
Source Project: neo4j-ml-procedures   Source File: DL4JMLModel.java    License: 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 24
Source Project: SnowGraph   Source File: JiraUtils.java    License: 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 25
Source Project: SnowGraph   Source File: JiraUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void createIssueCommentNode(IssueCommentInfo issueCommentInfo, Node node) {
    node.addLabel(Label.label(JiraExtractor.ISSUECOMMENT));
    node.setProperty(JiraExtractor.ISSUECOMMENT_ID, issueCommentInfo.getCommentId());
    node.setProperty(JiraExtractor.ISSUECOMMENT_BODY, issueCommentInfo.getBody());
    node.setProperty(JiraExtractor.ISSUECOMMENT_CREATOR_NAME, issueCommentInfo.getCreatorName());
    node.setProperty(JiraExtractor.ISSUECOMMENT_UPDATER_NAME, issueCommentInfo.getUpdaterName());
    node.setProperty(JiraExtractor.ISSUECOMMENT_CREATED_DATE, issueCommentInfo.getCreatedDate());
    node.setProperty(JiraExtractor.ISSUECOMMENT_UPDATED_DATE, issueCommentInfo.getUpdatedDate());
}
 
Example 26
Source Project: SnowGraph   Source File: JiraUtils.java    License: 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 27
Source Project: SnowGraph   Source File: GitCommit.java    License: 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 28
Source Project: SnowGraph   Source File: MboxHandler.java    License: Apache License 2.0 5 votes vote down vote up
private static void createMailNode(Node node, String subject, String id, String senderName, String senderMail,
                                   String[] receiverNames, String[] receiverMails, String replyTo, String date, String body) {
    node.addLabel(Label.label(MailListExtractor.MAIL));
    node.setProperty(MailListExtractor.MAIL_SUBJECT, subject);
    node.setProperty(MailListExtractor.MAIL_ID, id);
    node.setProperty(MailListExtractor.MAIL_SENDER_NAME, senderName);
    node.setProperty(MailListExtractor.MAIL_SENDER_MAIL, senderMail);
    node.setProperty(MailListExtractor.MAIL_RECEIVER_NAMES, String.join(", ", receiverNames));
    node.setProperty(MailListExtractor.MAIL_RECEIVER_MAILS, String.join(", ", receiverMails));
    node.setProperty(MailListExtractor.MAIL_DATE, date);
    node.setProperty(MailListExtractor.MAIL_BODY, body);
    //node.setProperty(MailListExtractor.MAIL_MAIN_TEXT,MailUtil.extractMainText(body));
}
 
Example 29
Source Project: SnowGraph   Source File: BugzillaUtils.java    License: 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 30
Source Project: SnowGraph   Source File: GraphNodeUtil.java    License: 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, "");
}