org.neo4j.graphdb.Label Java Examples
The following examples show how to use
org.neo4j.graphdb.Label.
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: MboxHandler.java From SnowGraph with Apache License 2.0 | 6 votes |
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 #2
Source File: QaCommentInfo.java From SnowGraph with Apache License 2.0 | 6 votes |
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 #3
Source File: QuestionInfo.java From SnowGraph with Apache License 2.0 | 6 votes |
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 #4
Source File: AnswerInfo.java From SnowGraph with Apache License 2.0 | 6 votes |
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 #5
Source File: QaUserInfo.java From SnowGraph with Apache License 2.0 | 6 votes |
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 #6
Source File: GraphApi.java From SciGraph with Apache License 2.0 | 6 votes |
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 #7
Source File: GraphNodeUtil.java From SnowGraph with Apache License 2.0 | 6 votes |
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 #8
Source File: Neo4jUtil.java From trainbenchmark with Eclipse Public License 1.0 | 6 votes |
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 #9
Source File: JavaCodeUtils.java From SnowGraph with Apache License 2.0 | 6 votes |
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 #10
Source File: Neo4JDb.java From knowledge-extraction with Apache License 2.0 | 6 votes |
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 #11
Source File: UniqueRelationshipFactory.java From neo4jena with Apache License 2.0 | 6 votes |
/** * 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 #12
Source File: BugzillaUtils.java From SnowGraph with Apache License 2.0 | 6 votes |
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 #13
Source File: AbstractEmbeddedDBAccess.java From jcypher with Apache License 2.0 | 6 votes |
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 #14
Source File: Neo4jIndexer.java From elasticsearch-river-neo4j with Apache License 2.0 | 6 votes |
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 #15
Source File: Neo4jIndexer.java From elasticsearch-river-neo4j with Apache License 2.0 | 6 votes |
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 #16
Source File: Clique.java From SciGraph with Apache License 2.0 | 6 votes |
@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 File: JiraUtils.java From SnowGraph with Apache License 2.0 | 6 votes |
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 #18
Source File: ReferenceExtractor.java From SnowGraph with Apache License 2.0 | 6 votes |
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 #19
Source File: ReferenceExtractor.java From SnowGraph with Apache License 2.0 | 6 votes |
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 #20
Source File: Neo4jModule.java From SciGraph with Apache License 2.0 | 6 votes |
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 #21
Source File: Neo4jLiveTest.java From tutorials with MIT License | 6 votes |
@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 File: Neo4jEntityManager.java From extended-objects with Apache License 2.0 | 5 votes |
@Override public EmbeddedNode createEntity(DynamicType<EntityTypeMetadata<NodeMetadata<EmbeddedLabel>>> types, Set<EmbeddedLabel> discriminators, Map<PrimitivePropertyMethodMetadata<PropertyMetadata>, Object> example) { Label[] labels = new Label[discriminators.size()]; int i = 0; for (EmbeddedLabel discriminator : discriminators) { labels[i++] = discriminator.getDelegate(); } EmbeddedNode node = new EmbeddedNode(graphDatabaseService.createNode(labels)); setProperties(node, example); return node; }
Example #23
Source File: EmbeddedNode.java From extended-objects with Apache License 2.0 | 5 votes |
public EmbeddedNode(Node delegate) { super(delegate.getId(), delegate); this.labels = new HashSet<>(); for (Label label : delegate.getLabels()) { labels.add(new EmbeddedLabel(label)); } }
Example #24
Source File: Neo4jIndexerTest.java From elasticsearch-river-neo4j with Apache License 2.0 | 5 votes |
@Before public void before() { worker = mock(ElasticOperationWorker.class); db = mock(SpringCypherRestGraphDatabase.class); List<Label> labels = new ArrayList<>(); labels.add(DynamicLabel.label("User")); indexer = new Neo4jIndexer(db, worker, new SimpleIndexingStrategy(), new SimpleDeletingStrategy(), "myindex", "mytype", labels); }
Example #25
Source File: GraphBatchImpl.java From SciGraph with Apache License 2.0 | 5 votes |
@Override public void addLabel(long node, Label label) { synchronized (graphLock) { Set<Label> labels = newLinkedHashSet(inserter.getNodeLabels(node)); labels.add(label); inserter.setNodeLabels(node, labels.toArray(new Label[labels.size()])); } }
Example #26
Source File: CategoryLabeler.java From SciGraph with Apache License 2.0 | 5 votes |
@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 #27
Source File: Clique.java From SciGraph with Apache License 2.0 | 5 votes |
private boolean containsOneLabel(Node n, Set<Label> labels) { for (Label l : labels) { if (n.hasLabel(l)) { return true; } } return false; }
Example #28
Source File: GraphOwlVisitor.java From SciGraph with Apache License 2.0 | 5 votes |
private long getOrCreateNode(String iri, Label... labels) { Optional<Long> node = graph.getNode(iri); if (!node.isPresent()) { long nodeId = graph.createNode(iri); graph.setNodeProperty(nodeId, CommonProperties.IRI, iri); node = Optional.of(nodeId); } for (Label label : labels) { graph.addLabel(node.get(), label); } return node.get(); }
Example #29
Source File: NodeTransformer.java From SciGraph with Apache License 2.0 | 5 votes |
@Override public Concept apply(Node n) { try (Transaction tx = n.getGraphDatabase().beginTx()) { Concept concept = new Concept(n.getId()); concept.setIri((String) n.getProperty(Concept.IRI, null)); concept.setAnonymous(n.hasLabel(OwlLabels.OWL_ANONYMOUS)); concept.setDeprecated(isDeprecated(n)); for (String definition : GraphUtil.getProperties(n, Concept.DEFINITION, String.class)) { concept.addDefinition(definition); } for (String abbreviation : GraphUtil.getProperties(n, Concept.ABREVIATION, String.class)) { concept.addAbbreviation(abbreviation); } for (String acronym : GraphUtil.getProperties(n, Concept.ACRONYM, String.class)) { concept.addAcronym(acronym); } for (String category : GraphUtil.getProperties(n, Concept.CATEGORY, String.class)) { concept.addCategory(category); } for (String label : GraphUtil.getProperties(n, Concept.LABEL, String.class)) { concept.addLabel(label); } for (String synonym : GraphUtil.getProperties(n, Concept.SYNONYM, String.class)) { concept.addSynonym(synonym); } for (Label type : n.getLabels()) { concept.addType(type.name()); } for (Relationship r: n.getRelationships(OwlRelationships.OWL_EQUIVALENT_CLASS)) { Node equivalence = r.getStartNode().equals(n) ? r.getEndNode() : r.getStartNode(); concept.getEquivalentClasses().add((String)equivalence.getProperty(CommonProperties.IRI)); } tx.success(); return concept; } }
Example #30
Source File: GraphTransactionalImpl.java From SciGraph with Apache License 2.0 | 5 votes |
@Override public Collection<Label> getLabels(long nodeId) { try (Transaction tx = graphDb.beginTx()) { Node node = graphDb.getNodeById(nodeId); Collection<Label> labels = newArrayList(node.getLabels()); tx.success(); return labels; } }