org.neo4j.graphdb.Result Java Examples

The following examples show how to use org.neo4j.graphdb.Result. 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: CustomerProceduresTest.java    From ongdb-lab-apoc with Apache License 2.0 6 votes vote down vote up
@Test
    public void testRecommend() {
        GraphDatabaseService db = neo4j.getGraphDatabaseService();

        try (Transaction tx = db.beginTx()) {
            // CALL training.recommendOnly("Dee Dee Titley_0_linkedin") YIELD stringObjectMap RETURN stringObjectMap
//            Result res = db.execute("CALL training.recommendOnly(\"Dee Dee Titley_0_linkedin\") YIELD stringObjectMap RETURN stringObjectMap");

            Result res = db.execute("CALL zdr.index.search('linkin', 'name:china*', 10) YIELD node RETURN node");

//
//            System.out.println(res.resultAsString());
//            System.out.println(res.next());
//            Node node = (Node) res.next().get("stringObjectMap");
//            CustomerProcedures.Movie movie = (CustomerProcedures.Movie) res.next().get("stringObjectMap");
//            movie.stringObjectMap.forEach((k, v) -> System.out.println("key:value = " + k + ":" + v));
//            System.out.println(node.getId());
//            System.out.println(node.getLabels());
//            System.out.println(node.getRelationships());

        }
    }
 
Example #2
Source File: VocabularyNeo4jImpl.java    From SciGraph with Apache License 2.0 6 votes vote down vote up
@Override
public Set<String> getAllCategories() {
  return Suppliers.memoize(new Supplier<Set<String>>() {
    @Override
    public Set<String> get() {
      Result result =
          graph.execute("START n = node(*) WHERE exists(n.category) RETURN distinct(n.category)");
      Set<String> categories = new HashSet<>();
      while (result.hasNext()) {
        Map<String, Object> col = result.next();
        Object category = col.get("(n.category)");
        if (category.getClass().isArray()) {
          for (String cat : (String[]) category) {
            categories.add(cat);
          }
        } else {
          categories.add((String) col.get("(n.category)"));
        }
      }
      return categories;
    }
  }).get();
}
 
Example #3
Source File: HyperGeometricAnalyzer.java    From SciGraph with Apache License 2.0 6 votes vote down vote up
private Set<AnalyzerInnerNode> getCompleteSetNodes(AnalyzeRequest request) throws Exception {
  String query =
      "match (r)<-[:subClassOf*]-(n)" + request.getPath()
          + "(i) where id(r) = "
          + getNodeIdFromIri(request.getOntologyClass()) + " with n, i as t return t, count(distinct n)";
  //System.out.println(query);
  Result result2 = cypherUtil.execute(query);
  Set<AnalyzerInnerNode> allSubjects = new HashSet<>();
  while (result2.hasNext()) {
    Map<String, Object> map = result2.next();
    Long count = (Long) map.get("count(distinct n)");
    Long nodeId = ((Node) map.get("t")).getId();
    allSubjects.add(new AnalyzerInnerNode(nodeId, count));
    allSubjects.addAll(resolveToParents(nodeId, count));
  }
  return allSubjects;
}
 
Example #4
Source File: GraphApi.java    From SciGraph with Apache License 2.0 6 votes vote down vote up
public Graph getEdges(RelationshipType type, boolean entail, long skip, long limit) {
  String query = "MATCH path = (start)-[r:" + type.name() + (entail ? "!" : "") + "]->(end) "
      + " RETURN path "
      // TODO: This slows down the query dramatically.
      // + " ORDER BY ID(r) "
      + " SKIP " + skip + " LIMIT " + limit;
  Graph graph = new TinkerGraph();
  TinkerGraphUtil tgu = new TinkerGraphUtil(graph, curieUtil);
  Result result;
  try {
    result = cypherUtil.execute(query);
    while (result.hasNext()) {
      Map<String, Object> map = result.next();
      Path path = (Path) map.get("path");
      tgu.addPath(path);
    }
  } catch (ArrayIndexOutOfBoundsException e) {
    // Return and empty graph if the limit is too high...
  }
  return graph;
}
 
Example #5
Source File: Neo4jLiveTest.java    From tutorials with 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 #6
Source File: DeepGLIntegrationTest.java    From ml-models with Apache License 2.0 6 votes vote down vote up
@Test
public void write() throws Exception {

    String writeProperty = "'foo'";
    Result result = db.execute("CALL embedding.deepgl('Node', 'TYPE', {writeProperty: " + writeProperty + ", nodeFeatures:['prop1']})");

    while (result.hasNext()) {
        System.out.println("summary = " + result.next());
    }

    Result embeddings = db.execute("MATCH (n:Node) RETURN n.foo AS foo");
    while(embeddings.hasNext()) {
        Map<String, Object> row = embeddings.next();
        System.out.println("embeddings = " + Arrays.toString((double[])row.get("foo")));
    }
}
 
Example #7
Source File: QueryEngine.java    From paprika with GNU Affero General Public License v3.0 6 votes vote down vote up
public List<String> findKeysFromPackageName(String appName) throws CypherException, IOException {
    ArrayList<String> keys = new ArrayList<>();
    try (Transaction ignored = graphDatabaseService.beginTx()) {
        Result result = graphDatabaseService.execute("MATCH (n:App) WHERE n.package='"+appName+"' RETURN n.app_key as key");
        while ( result.hasNext() )
        {
            Map<String,Object> row = result.next();
            keys.add((String) row.get("key"));
        }
    }
    return keys;
}
 
Example #8
Source File: Neo4jLiveTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void testBindings() {
    graphDb.beginTx();

    Map<String, Object> params = new HashMap<>();
    params.put("name", "baeldung");
    params.put("make", "tesla");
    params.put("model", "modelS");

    Result result = graphDb.execute("CREATE (baeldung:Company {name:$name}) " +
            "-[:owns]-> (tesla:Car {make: $make, model: $model})" +
            "RETURN baeldung, tesla", params);

    Map<String, Object> firstResult = result.next();
    Assert.assertTrue(firstResult.containsKey("baeldung"));
    Assert.assertTrue(firstResult.containsKey("tesla"));

    Node car = (Node) firstResult.get("tesla");
    Assert.assertEquals(car.getProperty("model"), "modelS");
}
 
Example #9
Source File: Neo4j.java    From SPADE with GNU General Public License v3.0 6 votes vote down vote up
@Override
    public Object executeQuery(String query)
    {
        try ( Transaction tx = graphDb.beginTx() )
        {
            Result result = null;
//            globalTxCheckin();
            try
            {
                result = graphDb.execute(query);
            }
            catch(QueryExecutionException ex)
            {
                logger.log(Level.SEVERE, "Neo4j Cypher query execution not successful!", ex);
            }
            finally
            {
                tx.success();
            }
            return result;
        }
    }
 
Example #10
Source File: QuartileCalculator.java    From paprika with GNU Affero General Public License v3.0 6 votes vote down vote up
private Map calculeTresholds(Result result){
    Map<String, Double> res = new HashMap<>();
    //Only one result in that case
    while (result.hasNext())
    {
        Map<String,Object> row = result.next();
        //Sometime neo4J return a double or an int... With toString it's works in all cases
        double q1 = Double.valueOf(row.get("Q1").toString());
        double med = Double.valueOf(row.get("MED").toString());
        double q3 = Double.valueOf(row.get("Q3").toString());
        double high  = q3 + ( 1.5 * ( q3 - q1));
        double very_high  = q3 + ( 3 * ( q3 - q1));
        res.put("Q1",q1);
        res.put("Q3",q3);
        res.put("MED",med);
        res.put("HIGH (1.5)",high);
        res.put("VERY HIGH (3.0)",very_high);
    }
    return res;
}
 
Example #11
Source File: CypherUtil.java    From SciGraph with Apache License 2.0 6 votes vote down vote up
Set<String> getEntailedRelationshipNames(Collection<String> parents) {
  Set<String> entailedTypes = new HashSet<>();
  for (String parent : parents) {
    entailedTypes.add(parent);
    Map<String, Object> params = new HashMap<>();
    params.put("iri", parent);
    try (Transaction tx = graphDb.beginTx()) {
      Result result =
          graphDb.execute("START parent=node:node_auto_index(iri={iri}) "
              + "MATCH (parent)<-[:subPropertyOf|equivalentProperty*]-(subProperty) "
              + "RETURN distinct subProperty.iri as subProperty", params);
      while (result.hasNext()) {
        Map<String, Object> map = result.next();
        entailedTypes.add((String) map.get("subProperty"));
      }
      tx.success();
    }
  }
  return entailedTypes;
}
 
Example #12
Source File: HashMapUsageQuery.java    From paprika with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void execute(boolean details) throws CypherException, IOException {
    Result result;
    try (Transaction ignored = graphDatabaseService.beginTx()) {
        String query = "MATCH (m:Method)-[:CALLS]->(e:ExternalMethod{full_name:'<init>#java.util.HashMap'}) return m.app_key";
        if(details){
            query += ",m.full_name as full_name";
        }else{
            query += ", count(m) as HMU";
        }
        result = graphDatabaseService.execute(query);
        queryEngine.resultToCSV(result, "_HMU.csv");
    }
}
 
Example #13
Source File: HyperGeometricAnalyzer.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
private Set<AnalyzerInnerNode> getSampleSetNodes(AnalyzeRequest request) throws Exception {
  Map<Long, AnalyzerInnerNode> sampleNodes = new HashMap<Long, AnalyzerInnerNode>();
  List<Long> sampleSetId = new ArrayList<>();
  for (String sample : request.getSamples()) {
    sampleSetId.add(getNodeIdFromIri(sample));
  }
  String query =
      "match (r)<-[:subClassOf*]-(n)" + request.getPath()
          + "(i) where id(n) in " + sampleSetId + " and id(r) = "
          + getNodeIdFromIri(request.getOntologyClass()) + " with n, i as t return t, count(distinct n)";
  //System.out.println(query);
  Result result = cypherUtil.execute(query);
  while (result.hasNext()) {
    Map<String, Object> map = result.next();
    Long count = (Long) map.get("count(distinct n)");
    Long nodeId = ((Node) map.get("t")).getId();
    sampleNodes.put(nodeId, new AnalyzerInnerNode(nodeId, count));
    for(AnalyzerInnerNode parentToAdd: resolveToParents(nodeId, count)){
      if(sampleNodes.containsKey(parentToAdd.getNodeId())){
        AnalyzerInnerNode existingNode = sampleNodes.get(parentToAdd.getNodeId());
        sampleNodes.put(existingNode.getNodeId(),new  AnalyzerInnerNode(existingNode.getNodeId(), existingNode.getCount() + parentToAdd.getCount()));
      }else{
        sampleNodes.put(parentToAdd.getNodeId(), parentToAdd);
      }
    }
  }
  return new HashSet<AnalyzerInnerNode>(sampleNodes.values());
}
 
Example #14
Source File: HeavyBroadcastReceiverQuery.java    From paprika with GNU Affero General Public License v3.0 5 votes vote down vote up
public void execute(boolean details) throws CypherException, IOException {
    Result result;
    try (Transaction ignored = graphDatabaseService.beginTx()) {
        String query = "MATCH (c:Class{is_broadcast_receiver:true})-[:CLASS_OWNS_METHOD]->(m:Method{name:'onReceive'}) WHERE m.number_of_instructions > "+veryHigh_noi+" AND m.cyclomatic_complexity>"+veryHigh_cc+" return m.app_key as app_key";
        if(details){
            query += ",m.full_name as full_name";
        }else{
            query += ",count(m) as HBR";
        }
        result = graphDatabaseService.execute(query);
        queryEngine.resultToCSV(result,"_HBR_NO_FUZZY.csv");
    }
}
 
Example #15
Source File: OverdrawQuery.java    From paprika with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void execute(boolean details) throws CypherException, IOException {
    try (Transaction ignored = graphDatabaseService.beginTx()) {
        String query = "MATCH (:Class{parent_name:\"android.view.View\"})-[:CLASS_OWNS_METHOD]->(n:Method{name:\"onDraw\"})-[:METHOD_OWNS_ARGUMENT]->(:Argument{position:1,name:\"android.graphics.Canvas\"}) \n" +
                "WHERE NOT n-[:CALLS]->(:ExternalMethod{full_name:\"clipRect#android.graphics.Canvas\"}) AND NOT n-[:CALLS]->(:ExternalMethod{full_name:\"quickReject#android.graphics.Canvas\"})\n" +
                "RETURN n.app_key as app_key";
        if(details){
            query += ",n.full_name as full_name";
        }else{
            query += ",count(n) as UIO";
        }
        Result result = graphDatabaseService.execute(query);
        queryEngine.resultToCSV(result, "_UIO.csv");
    }
}
 
Example #16
Source File: IGSQuery.java    From paprika with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void execute(boolean details) throws CypherException, IOException {
    try (Transaction ignored = graphDatabaseService.beginTx()) {
        String query = "MATCH (a:App) WITH a.app_key as key MATCH (cl:Class {app_key: key})-[:CLASS_OWNS_METHOD]->(m1:Method {app_key: key})-[:CALLS]->(m2:Method {app_key: key}) WHERE (m2.is_setter OR m2.is_getter) AND cl-[:CLASS_OWNS_METHOD]->m2 RETURN m1.app_key as app_key";
        if(details){
            query += ",m1.full_name as full_name,m2.full_name as gs_name";
        }else{
            query += ",count(m1) as IGS";
        }
        Result result = graphDatabaseService.execute(query);
        queryEngine.resultToCSV(result, "_IGS.csv");
    }
}
 
Example #17
Source File: CCQuery.java    From paprika with GNU Affero General Public License v3.0 5 votes vote down vote up
public void execute(boolean details) throws CypherException, IOException {
    Result result;
    try (Transaction ignored = graphDatabaseService.beginTx()) {
        String query = "MATCH (cl:Class) WHERE cl.class_complexity > "+ veryHigh +" RETURN cl.app_key as app_key";
        if(details){
            query += ",cl.name as full_name";
        }else{
            query += ",count(cl) as CC";
        }
        result = graphDatabaseService.execute(query);
        queryEngine.resultToCSV(result,"_CC_NO_FUZZY.csv");
    }
}
 
Example #18
Source File: CCQuery.java    From paprika with GNU Affero General Public License v3.0 5 votes vote down vote up
public void executeFuzzy(boolean details) throws CypherException, IOException {
        Result result;
        try (Transaction ignored = graphDatabaseService.beginTx()) {
            String query = "MATCH (cl:Class) WHERE cl.class_complexity > " + high + " RETURN cl.app_key as app_key, cl.class_complexity as class_complexity";
            if(details){
                query += ",cl.name as full_name";
            }
            result = graphDatabaseService.execute(query);
            List<String> columns = new ArrayList<>(result.columns());
            columns.add("fuzzy_value");
            int cc;
            List<Map> fuzzyResult = new ArrayList<>();
            File fcf = new File(fclFile);
            //We look if the file is in a directory otherwise we look inside the jar
            FIS fis;
            if(fcf.exists() && !fcf.isDirectory()){
                fis = FIS.load(fclFile, false);
            }else{
                fis = FIS.load(getClass().getResourceAsStream(fclFile),false);
            }
            FunctionBlock fb = fis.getFunctionBlock(null);
            while(result.hasNext()){
                HashMap res = new HashMap(result.next());
                cc = (int) res.get("class_complexity");
                if(cc >= veryHigh){
                    res.put("fuzzy_value", 1);
                }else {
                    fb.setVariable("class_complexity",cc);
                    fb.evaluate();
                    res.put("fuzzy_value", fb.getVariable("res").getValue());
                }
                fuzzyResult.add(res);
                }
                queryEngine.resultToCSV(fuzzyResult,columns,"_CC.csv");
        }
}
 
Example #19
Source File: HeavyServiceStartQuery.java    From paprika with GNU Affero General Public License v3.0 5 votes vote down vote up
public void executeFuzzy(boolean details) throws CypherException, IOException {
        Result result;
        try (Transaction ignored = graphDatabaseService.beginTx()) {
            String query = "MATCH (c:Class{is_service:true})-[:CLASS_OWNS_METHOD]->(m:Method{name:'onStartCommand'}) WHERE m.number_of_instructions > "+high_noi+" AND m.cyclomatic_complexity>"+high_cc+" return m.app_key as app_key,m.cyclomatic_complexity as cyclomatic_complexity, m.number_of_instructions as number_of_instructions";
            if(details){
                query += ",m.full_name as full_name";
            }
            result = graphDatabaseService.execute(query);
            List<String> columns = new ArrayList<>(result.columns());
            columns.add("fuzzy_value");
            int noi,cc;
            List<Map> fuzzyResult = new ArrayList<>();
            File fcf = new File(fclFile);
            //We look if the file is in a directory otherwise we look inside the jar
            FIS fis;
            if(fcf.exists() && !fcf.isDirectory()){
                fis = FIS.load(fclFile, false);
            }else{
                fis = FIS.load(getClass().getResourceAsStream(fclFile),false);
            }
            FunctionBlock fb = fis.getFunctionBlock(null);
            while(result.hasNext()){
                HashMap res = new HashMap(result.next());
                cc = (int) res.get("cyclomatic_complexity");
                noi = (int) res.get("number_of_instructions");
                if(cc >= veryHigh_cc && noi >= veryHigh_noi){
                    res.put("fuzzy_value", 1);
                }else {
                    fb.setVariable("cyclomatic_complexity",cc);
                    fb.setVariable("number_of_instructions",noi);
                    fb.evaluate();
                    res.put("fuzzy_value", fb.getVariable("res").getValue());
                }
                fuzzyResult.add(res);
                }
                queryEngine.resultToCSV(fuzzyResult,columns,"_HSS.csv");
        }
}
 
Example #20
Source File: NLMRQuery.java    From paprika with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void execute(boolean details) throws CypherException, IOException {
    try (Transaction ignored = graphDatabaseService.beginTx()) {
        String query = "MATCH (cl:Class) WHERE HAS(cl.is_activity) AND NOT (cl:Class)-[:CLASS_OWNS_METHOD]->(:Method { name: 'onLowMemory' }) AND NOT cl-[:EXTENDS]->(:Class) RETURN cl.app_key as app_key";
        if(details){
            query += ",cl.name as full_name";
        }else{
            query += ",count(cl) as NLMR";
        }
        Result result = graphDatabaseService.execute(query);
        queryEngine.resultToCSV(result, "_NLMR.csv");
    }
}
 
Example #21
Source File: UnsupportedHardwareAccelerationQuery.java    From paprika with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void execute(boolean details) throws CypherException, IOException {
    Result result;
    String [] uhas = {
            "drawPicture#android.graphics.Canvas",
            "drawVertices#android.graphics.Canvas",
            "drawPosText#android.graphics.Canvas",
            "drawTextOnPath#android.graphics.Canvas",
            "drawPath#android.graphics.Canvas",
            "setLinearText#android.graphics.Paint",
            "setMaskFilter#android.graphics.Paint",
            "setPathEffect#android.graphics.Paint",
            "setRasterizer#android.graphics.Paint",
            "setSubpixelText#android.graphics.Paint"
    };
    String query = "MATCH (m:Method)-[:CALLS]->(e:ExternalMethod) WHERE e.full_name='"+uhas[0]+"'";
    for (int i=1; i < uhas.length;i++){
        query += " OR e.full_name='" + uhas[i] + "' ";
    }
    query += "return m.app_key";
    if(details){
        query += ",m.full_name as full_name";
    }else{
        query += ",count(m) as UHA";
    }
    try (Transaction ignored = graphDatabaseService.beginTx()) {
        result = graphDatabaseService.execute(query);
        queryEngine.resultToCSV(result, "_UHA.csv");
    }
}
 
Example #22
Source File: QuartileCalculator.java    From paprika with GNU Affero General Public License v3.0 5 votes vote down vote up
public void calculateNumberOfAttributesQuartile() throws IOException {
    Map<String, Double> res;
    Result result;
    try (Transaction ignored = graphDatabaseService.beginTx()) {
        String query = "MATCH (n:Class) WHERE NOT HAS(n.is_interface) AND NOT HAS(n.is_abstract) RETURN percentileCont(n.number_of_attributes,0.25) as Q1, percentileCont(n.number_of_attributes,0.5) as MED, percentileCont(n.number_of_attributes,0.75) as Q3";
        result = graphDatabaseService.execute(query);
        res = calculeTresholds(result);
    }
    queryEngine.statsToCSV(res, "_STAT_NB_ATTRIBUTES.csv");
}
 
Example #23
Source File: QuartileCalculator.java    From paprika with GNU Affero General Public License v3.0 5 votes vote down vote up
public void calculateNumberOfMethodsQuartile() throws IOException {
    Map<String, Double> res;
    Result result;
    try (Transaction ignored = graphDatabaseService.beginTx()) {
        String query = "MATCH (n:Class) WHERE NOT HAS(n.is_interface) AND NOT HAS(n.is_abstract) RETURN percentileCont(n.number_of_methods,0.25) as Q1, percentileCont(n.number_of_methods,0.5) as MED, percentileCont(n.number_of_methods,0.75) as Q3";
        result = graphDatabaseService.execute(query);
        res = calculeTresholds(result);
    }
    queryEngine.statsToCSV(res, "_STAT_NB_METHODS.csv");
}
 
Example #24
Source File: TinkerGraphUtil.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
public Graph resultToGraph(Result result) {
  graph = new TinkerGraph();
  while (result.hasNext()) {
    Map<String, Object> map = result.next();
    for (Map.Entry<String, Object> entry : map.entrySet()) {
      Object value = entry.getValue();
      String key = entry.getKey();
      if (null == value) {
        continue;
      } else if (value instanceof PropertyContainer) {
        addElement((PropertyContainer) value);
      } else if (value instanceof Path) {
        for (PropertyContainer container : (Path) value) {
          addElement(container);
        }
      } else if (value instanceof ArrayList) {
        for (Object thing : (ArrayList<?>) value) {
          if (thing instanceof PropertyContainer) {
            addElement((PropertyContainer) thing);
          }
        }
      } else if (value instanceof Boolean) {
        // generates a lonely node which contains the result
        Vertex vertex = graph.addVertex(key);
        vertex.setProperty(key, value);
        vertex.setProperty(NodeProperties.LABEL, "Boolean result");
        vertex.setProperty(CommonProperties.IRI, key);
      } else {
        logger.warning("Not converting " + value.getClass() + " to tinker graph");
      }
    }
  }
  return graph;
}
 
Example #25
Source File: QuartileCalculator.java    From paprika with GNU Affero General Public License v3.0 5 votes vote down vote up
public void calculateNumberOfMethodsForInterfacesQuartile() throws IOException {
    Map<String, Double> res;
    Result result;
    try (Transaction ignored = graphDatabaseService.beginTx()) {
        String query = "MATCH (n:Class) WHERE HAS(n.is_interface) RETURN percentileCont(n.number_of_methods,0.25) as Q1, percentileCont(n.number_of_methods,0.5) as MED, percentileCont(n.number_of_methods,0.75) as Q3";
        result = graphDatabaseService.execute(query);
        res = calculeTresholds(result);
    }
    queryEngine.statsToCSV(res, "_STAT_NB_METHODS_INTERFACE.csv");
}
 
Example #26
Source File: QuartileCalculator.java    From paprika with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Excluding classes implementing 0 or 1 interface
 * @return
 */
public void calculateNumberOfImplementedInterfacesQuartile() throws IOException {
    Map<String, Double> res;
    Result result;
    try (Transaction ignored = graphDatabaseService.beginTx()) {
        String query = "MATCH (n:Class) WHERE n.number_of_implemented_interfaces > 1 RETURN percentileCont(n.number_of_implemented_interfaces,0.25) as Q1, percentileCont(n.number_of_implemented_interfaces,0.5) as MED, percentileCont(n.number_of_implemented_interfaces,0.75) as Q3";
        result = graphDatabaseService.execute(query);
        res = calculeTresholds(result);
    }
    queryEngine.statsToCSV(res, "_STAT_NB_INTERFACES.csv");
}
 
Example #27
Source File: QuartileCalculator.java    From paprika with GNU Affero General Public License v3.0 5 votes vote down vote up
public Map calculateQuartile(String nodeType, String property){
    Result result;
    try (Transaction ignored = graphDatabaseService.beginTx()) {
        String query = "MATCH (n:" + nodeType + ") RETURN percentileCont(n." + property + ",0.25) as Q1,percentileCont(n." + property + ",0.5) as MED, percentileCont(n." + property + ",0.75) as Q3";
        result = graphDatabaseService.execute(query);
        return calculeTresholds(result);
    }
}
 
Example #28
Source File: QuartileCalculator.java    From paprika with GNU Affero General Public License v3.0 5 votes vote down vote up
public void calculateNumberofInstructionsQuartile() throws IOException {
    Map<String, Double> res;
    Result result;
    try (Transaction ignored = graphDatabaseService.beginTx()) {
        String query = "MATCH (n:Method) WHERE NOT HAS(n.is_getter) AND NOT HAS(n.is_setter) AND n.number_of_instructions > 0 RETURN percentileCont(n.number_of_instructions,0.25) as Q1, percentileCont(n.number_of_instructions,0.5) as MED, percentileCont(n.number_of_instructions,0.75) as Q3";
        result = graphDatabaseService.execute(query);
        res = calculeTresholds(result);
    }
    queryEngine.statsToCSV(res, "_STAT_NB_INSTRUCTIONS.csv");
}
 
Example #29
Source File: QuartileCalculator.java    From paprika with GNU Affero General Public License v3.0 5 votes vote down vote up
public void calculateClassComplexityQuartile() throws IOException {
    Map<String, Double> res;
    Result result;
    try (Transaction ignored = graphDatabaseService.beginTx()) {
        String query = "MATCH (n:Class) WHERE NOT HAS(n.is_interface) AND NOT HAS(n.is_abstract) RETURN percentileCont(n.class_complexity,0.25) as Q1, percentileCont(n.class_complexity,0.5) as MED, percentileCont(n.class_complexity,0.75) as Q3";
        result = graphDatabaseService.execute(query);
        res = calculeTresholds(result);
    }
    queryEngine.statsToCSV(res, "_STAT_CLASS_COMPLEXITY.csv");
}
 
Example #30
Source File: OwlPostprocessor.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
public void processSomeValuesFrom() {
  logger.info("Processing someValuesFrom classes");
  try (Transaction tx = graphDb.beginTx()) {
    Result results =
        graphDb.execute("MATCH (n)-[relationship]->(svf:someValuesFrom)-[:property]->(p) "
            + "RETURN n, relationship, svf, p");
    while (results.hasNext()) {
      Map<String, Object> result = results.next();
      Node subject = (Node) result.get("n");
      Relationship relationship = (Relationship) result.get("relationship");
      Node svf = (Node) result.get("svf");
      Node property = (Node) result.get("p");
      for (Relationship r : svf.getRelationships(OwlRelationships.FILLER)) {
        Node object = r.getEndNode();
        String relationshipName =
            GraphUtil.getProperty(property, CommonProperties.IRI, String.class).get();
        RelationshipType type = RelationshipType.withName(relationshipName);
        String propertyUri =
            GraphUtil.getProperty(property, CommonProperties.IRI, String.class).get();
        Relationship inferred = subject.createRelationshipTo(object, type);
        inferred.setProperty(CommonProperties.IRI, propertyUri);
        inferred.setProperty(CommonProperties.CONVENIENCE, true);
        inferred.setProperty(CommonProperties.OWL_TYPE, relationship.getType().name());
      }
    }
    tx.success();
    tx.close();
  }
}