Java Code Examples for org.neo4j.graphdb.Node#hasProperty()
The following examples show how to use
org.neo4j.graphdb.Node#hasProperty() .
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: Find_data_paths.java From EvilCoder with MIT License | 6 votes |
public static void print_path(Joern_db joern_db, List<Long> path, List<String> var_names) { for(int i=0, i_end=path.size(); i<i_end; ++i) { Long p = path.get(i); Node node = (Node)(Pipeline.v(p).to_list().get(0)); if(node.hasProperty("code")) { System.out.println(p.toString() + "\t" + (String)(node.getProperty("code"))); } else { System.out.println(p.toString()); } if(var_names != null && i < path.size()-1) { System.out.println("\t" + var_names.get(i)); } } }
Example 2
Source File: Location.java From EvilCoder with MIT License | 6 votes |
public static String get_location_for_node_id(Joern_db joern_db, Long node_id) throws Exception { Long cur_id = node_id; String location = null; while(true) { List<Node> nodes = Pipeline.v(cur_id).to_list(); Node first = nodes.get(0); if(first.hasProperty("location")) { location = (String)(first.getProperty("location")); break; } cur_id = get_general_parent(joern_db, cur_id); // print "cur_id:", cur_id } return location; }
Example 3
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 4
Source File: AnonymousNodeTagger.java From SciGraph with Apache License 2.0 | 6 votes |
@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 5
Source File: GraphTransactionalImpl.java From SciGraph with Apache License 2.0 | 5 votes |
@Override public void addNodeProperty(long nodeId, String property, Object value) { if (GraphUtil.ignoreProperty(value)) { return; } try (Transaction tx = graphDb.beginTx()) { Node node = graphDb.getNodeById(nodeId); if (node.hasProperty(property)) { node.setProperty(property, GraphUtil.getNewPropertyValue(node.getProperty(property), value)); } else { node.setProperty(property, value); } tx.success(); } }
Example 6
Source File: GraphTransactionalImpl.java From SciGraph with Apache License 2.0 | 5 votes |
@Override public <T> Optional<T> getNodeProperty(long nodeId, String property, Class<T> type) { try (Transaction tx = graphDb.beginTx()) { Node node = graphDb.getNodeById(nodeId); Optional<T> value = Optional.<T> empty(); if (node.hasProperty(property)) { value = Optional.<T> of(type.cast(node.getProperty(property))); } tx.success(); return value; } }
Example 7
Source File: GraphTransactionalImpl.java From SciGraph with Apache License 2.0 | 5 votes |
@Override public <T> Collection<T> getNodeProperties(long nodeId, String property, Class<T> type) { try (Transaction tx = graphDb.beginTx()) { Node node = graphDb.getNodeById(nodeId); Set<T> set = emptySet(); if (node.hasProperty(property)) { set = GraphUtil.getPropertiesAsSet(node.getProperty(property), type); } tx.success(); return set; } }
Example 8
Source File: NodeTransformer.java From SciGraph with Apache License 2.0 | 5 votes |
static boolean isDeprecated(Node n) { if (!n.hasProperty(OWLRDFVocabulary.OWL_DEPRECATED.toString())) { return false; } if (n.getProperty(OWLRDFVocabulary.OWL_DEPRECATED.toString()) instanceof Boolean) { return (Boolean) n.getProperty(OWLRDFVocabulary.OWL_DEPRECATED.toString()); } else { return Boolean.valueOf((String)n.getProperty(OWLRDFVocabulary.OWL_DEPRECATED.toString(), "false")); } }
Example 9
Source File: Clique.java From SciGraph with Apache License 2.0 | 5 votes |
private void ensureLabel(Node leader, List<Node> clique) { // Move rdfs:label if non-existing on leader if (!leader.hasProperty(NodeProperties.LABEL)) { for (Node n : clique) { if (n.hasProperty(NodeProperties.LABEL) && n.hasProperty("http://www.w3.org/2000/01/rdf-schema#label")) { leader.setProperty(NodeProperties.LABEL, n.getProperty(NodeProperties.LABEL)); leader.setProperty("http://www.w3.org/2000/01/rdf-schema#label", n.getProperty("http://www.w3.org/2000/01/rdf-schema#label")); return; } } } }
Example 10
Source File: Clique.java From SciGraph with Apache License 2.0 | 5 votes |
private List<Node> designatedLeader(List<Node> clique) { List<Node> designatedNodes = new ArrayList<Node>(); for (Node n : clique) { if (n.hasProperty(leaderAnnotationProperty)) { designatedNodes.add(n); } } return designatedNodes; }
Example 11
Source File: PatternRecognitionResource.java From graphify with Apache License 2.0 | 5 votes |
/** * Gets a Neo4j node entity that contains the root pattern for performing hierarchical pattern recognition from. * @param db The Neo4j graph database service. * @return Returns a Neo4j node entity that contains the root pattern for performing hierarchical pattern recognition from. */ private static Node getRootPatternNode(GraphDatabaseService db) { Node patternNode; patternNode = new NodeManager().getOrCreateNode(GRAPH_MANAGER, GraphManager.ROOT_TEMPLATE, db); try(Transaction tx = db.beginTx()) { if (!patternNode.hasProperty("matches")) { patternNode.setProperty("matches", 0); patternNode.setProperty("threshold", GraphManager.MIN_THRESHOLD); patternNode.setProperty("root", 1); patternNode.setProperty("phrase", "{0} {1}"); } tx.success(); } return patternNode; }
Example 12
Source File: GraphManagerTest.java From graphify with Apache License 2.0 | 5 votes |
/** * Gets a Neo4j node entity that contains the root pattern for performing hierarchical pattern recognition from. * @param db The Neo4j graph database service. * @return Returns a Neo4j node entity that contains the root pattern for performing hierarchical pattern recognition from. */ private Node getRootPatternNode(GraphDatabaseService db, GraphManager graphManager) { Node patternNode; patternNode = graphManager.getOrCreateNode(GraphManager.ROOT_TEMPLATE, db); try(Transaction tx = db.beginTx()) { if (!patternNode.hasProperty("matches")) { patternNode.setProperty("matches", 0); patternNode.setProperty("threshold", GraphManager.MIN_THRESHOLD); patternNode.setProperty("root", 1); patternNode.setProperty("phrase", "{0} {1}"); } tx.success(); } return patternNode; }
Example 13
Source File: VectorUtilTest.java From graphify with Apache License 2.0 | 5 votes |
private static Node getRootPatternNode(GraphDatabaseService db, GraphManager graphManager) { Node patternNode; patternNode = new NodeManager().getOrCreateNode(graphManager, GraphManager.ROOT_TEMPLATE, db); try(Transaction tx = db.beginTx()) { if (!patternNode.hasProperty("matches")) { patternNode.setProperty("matches", 0); patternNode.setProperty("threshold", GraphManager.MIN_THRESHOLD); patternNode.setProperty("root", 1); patternNode.setProperty("phrase", "{0} {1}"); } tx.success(); } return patternNode; }
Example 14
Source File: ReadOptimizedGraphity.java From metalcon with GNU General Public License v3.0 | 5 votes |
/** * get a user's last recent status update's time stamp * * @param userReplica * replica of the user targeted * @return last recent status update's time stamp */ private static long getLastUpdateByReplica(final Node userReplica) { final Node user = NeoUtils.getNextSingleNode(userReplica, SocialGraphRelationshipType.REPLICA); if (user.hasProperty(Properties.User.LAST_UPDATE)) { return (long) user.getProperty(Properties.User.LAST_UPDATE); } return 0; }
Example 15
Source File: EdgeLabeler.java From SciGraph with Apache License 2.0 | 4 votes |
@Override public void run() { logger.info("Starting edge labeling..."); Map<String, String> map = new HashMap<String, String>(); int processedRels = 0; Transaction tx = graphDb.beginTx(); ResourceIterable<Relationship> rels = graphDb.getAllRelationships(); for (Relationship rel : rels) { if (processedRels % batchCommitSize == 0) { tx.success(); tx.close(); tx = graphDb.beginTx(); } String relName = rel.getType().name(); if (map.containsKey(relName)) { rel.setProperty(edgeProperty, map.get(relName)); } else { String relLabel = relName; String query = "START n = node:node_auto_index(iri='" + relName + "') match (n) return n"; Result result = graphDb.execute(query); if (result.hasNext()) { Node n = (Node) result.next().get("n"); if (n.hasProperty(NodeProperties.LABEL)) { relLabel = GraphUtil.getProperties(n, NodeProperties.LABEL, String.class).iterator().next(); } } rel.setProperty(edgeProperty, relLabel); map.put(relName, relLabel); } processedRels++; } logger.info(processedRels + " relations labeled."); tx.success(); tx.close(); }