Package net.sourceforge.jpowergraph.defaults

Examples of net.sourceforge.jpowergraph.defaults.DefaultGraph


      "http://dbpedia.org/property/birthPlace"
  };
  static Set<String> relations = new HashSet<String>(Arrays.asList(relationStrings));
 
  public static DefaultGraph createGraph(Concept concept){
    DefaultGraph graph = new DefaultGraph();
    ArrayList <Node> nodes = new ArrayList <Node> ();
    ArrayList <Edge> edges = new ArrayList <Edge> ();      
    Node conceptNode = new ConceptNode(concept.getConceptDescription().getName());
    Node superClassRoot = new PrintNode( ApplicationResources.getString("superclasses.node.root"));
    Node subClassRoot = new PrintNode( ApplicationResources.getString("subclasses.node.root"));
    Node relationsRoot = new PrintNode( ApplicationResources.getString("relations.node.root"));
    Node instancesRoot = new PrintNode( ApplicationResources.getString("instances.node.root"));
    Node instancesOfRoot = new PrintNode( ApplicationResources.getString("instancesOf.node.root"));
    nodes.add(superClassRoot);
    nodes.add(subClassRoot);
    nodes.add(relationsRoot);
    nodes.add(instancesRoot);
    nodes.add(instancesOfRoot);
    edges.add(new LineEdge(conceptNode,superClassRoot));
    edges.add(new LineEdge(conceptNode,subClassRoot));
    edges.add(new LineEdge(conceptNode,instancesRoot));
    edges.add(new LineEdge(conceptNode,relationsRoot));
    edges.add(new LineEdge(conceptNode,instancesRoot));
    edges.add(new LineEdge(conceptNode,instancesOfRoot));
    Node relatedNode = null;
    for (Relation r : concept.getRelations().getRelations()) {
      //For each conceptDescription in relation
      for (ConceptDescription conceptDescription : r.getConceptDescriptions()) {
        final String objectConceptUri = conceptDescription.getUri();
        if(objectConceptUri!=null ){
          if (r.getOnproperty() != null) {
            relatedNode = new RelationNode(conceptDescription.getName());           
            edges.add(new TextEdge(relationsRoot,relatedNode,formatRelation(r.getOnproperty())));           
          } else if (isSuperclassOfRelation(r)) {                     
            relatedNode = new SuperClassNode(conceptDescription.getName());           
            edges.add(new LineEdge(superClassRoot, relatedNode));
            } else {
              // otherwise, the object _is superclass of_ this, so...
              relatedNode = new SubClassNode(conceptDescription.getName());
              edges.add(new LineEdge(subClassRoot, relatedNode));
            }
          nodes.add(relatedNode);
          }
         
      }//End for each concept description in relation
    }//End for each relation
   
    addNodes(concept.getInstances().getConceptDescriptions(), nodes, edges, instancesRoot);
    addNodes(concept.getInstanceof().getConceptDescriptions(),nodes,edges,instancesOfRoot);   
    nodes.add(conceptNode);
    graph.addElements(nodes, edges);
    return graph;
  }
View Full Code Here


  public static String formatActivation(String conceptUri, Double value){
    return conceptUri+" "+formatter.format(value);
  }

  public static DefaultGraph createGraphFromOntoSpreadState(OntologyDAO ontologyDAO, OntoSpreadState ontoSpreadState) throws Exception{
    DefaultGraph graph = new DefaultGraph();
    ArrayList <Node> nodes = new ArrayList <Node> ();
    ArrayList <Edge> edges = new ArrayList <Edge> ();
    //FIXME: Refactor, using relations and draw instances and concepts, equals
    Node root = new PrintNode( ApplicationResources.getString("info.node.root"));
    Node initialRoot = new PrintNode( ApplicationResources.getString("initial.node.root"));
    Map<String, Double> concepts = ontoSpreadState.getConcepts();
    for (ScoredConceptTO initialConcept : ontoSpreadState.getInitialConcepts()) {
      ConceptTO conceptTO = ontologyDAO.getConceptTO(initialConcept.getConceptUri());
      Node node = new InitialNode(formatActivation(conceptTO.getName(),concepts.get(conceptTO.getUri())),conceptTO.getUri());
      edges.add(new LineEdge(initialRoot,node));
      nodes.add(node);
    }

    Node spreadedRoot = new PrintNode( ApplicationResources.getString("initial.node.spreaded"));
    for (String currentSpread : ontoSpreadState.getSpreadedConcepts()) {
      ConceptTO conceptTO = ontologyDAO.getConceptTO(currentSpread);
      Node currentNode = new SpreadNode(formatActivation(conceptTO.getName(),concepts.get(conceptTO.getUri())),conceptTO.getUri());
      edges.add(new LineEdge(spreadedRoot,currentNode));
      nodes.add(currentNode);
    }

    Node activatedRoot = new PrintNode(ApplicationResources.getString("initial.node.activated") );
    for (UriDepthPair activated : ontoSpreadState.getSortedList()) {
      ConceptTO conceptTO = ontologyDAO.getConceptTO(activated.getUri())
      Node currentNode = new ActivateNode(formatActivation(conceptTO.getName(),concepts.get(conceptTO.getUri())),conceptTO.getUri());
      edges.add(new ArrowEdge(activatedRoot,currentNode));
      nodes.add(currentNode);
    }
    //Creating skeleton of graph
    edges.add(new LineEdge(root,initialRoot));
    edges.add(new LineEdge(root,spreadedRoot));
    edges.add(new LineEdge(root,activatedRoot));
    nodes.add(root);
    nodes.add(initialRoot);
    nodes.add(spreadedRoot);
    nodes.add(activatedRoot);
    graph.addElements(nodes, edges);
    return graph;
  }
View Full Code Here

  }
 
  public static DefaultGraph createGraphForPath(OntologyDAO ontologyDAO, OntoSpreadState ontoSpreadState, ConceptTO conceptTO) throws Exception{
    Map<String, Double> concepts = ontoSpreadState.getConcepts();
    Map<String,PathTO[]> spreadPathTable = ontoSpreadState.getSpreadPathTable();
    DefaultGraph graph = new DefaultGraph();
    ArrayList <Node> nodes = new ArrayList <Node> ();
    ArrayList <Edge> edges = new ArrayList <Edge> ();
    ConceptTO pathConceptTO = null;
    Node spreadedNode = new ActivateNode(formatActivation(conceptTO.getName(),concepts.get(conceptTO.getUri())), conceptTO.getUri());
    Node activatedRoot = new PrintNode(ApplicationResources.getString("initial.node.activated") );
    for (String conceptUri : spreadPathTable.keySet()) {
      PathTO[]path = spreadPathTable.get(conceptUri);
      if(path[path.length-1].getConceptUri().equals(conceptTO.getUri()) && !conceptUri.equals(conceptTO.getUri())){
        Node sonNode = spreadedNode;
        for (int i = path.length-1; i >=0 ; i--) {
          pathConceptTO = ontologyDAO.getConceptTO(path[i].getConceptUri());
          Node pathNode = new PathNode(
              formatActivation(pathConceptTO.getName(),
                  concepts.get(pathConceptTO.getUri())),path[i].getConceptUri());
//          for(String relation:path[i].getRelationsUri()){
//            if(relation == null) relation = "#INITIAL";
//            edges.add(new TextEdge(pathNode,sonNode,""+formatRelation(relation))); 
//          }
          edges.add(new LineEdge(pathNode,sonNode));
          nodes.add(pathNode);
          sonNode = pathNode;
        }
        pathConceptTO = ontologyDAO.getConceptTO(conceptUri);       
        Node activateNode =
          new ActivationNode(
              formatActivation(pathConceptTO.getName(),
                  concepts.get(pathConceptTO.getUri())),
                  pathConceptTO.getUri());
        for(String relation:path[path.length-1].getRelationsUri()){
          if(relation != null)
            edges.add(new TextEdge(activatedRoot,activateNode,formatRelation(relation)))
        }       
        nodes.add(activateNode);
      }//If activated by current spread node
    }
    edges.add(new ArrowEdge(spreadedNode,activatedRoot));
    nodes.add(activatedRoot);
    nodes.add(spreadedNode);
    graph.addElements(nodes, edges);
    return graph;
  }
View Full Code Here

  }
 
  public static DefaultGraph createGraphForSpreading(OntologyDAO ontologyDAO, OntoSpreadState ontoSpreadState, ConceptTO conceptTO) throws Exception{
    Map<String, Double> concepts = ontoSpreadState.getConcepts();
    Map<String,PathTO[]> spreadPathTable = ontoSpreadState.getSpreadPathTable();
    DefaultGraph graph = new DefaultGraph();
    ArrayList <Node> nodes = new ArrayList <Node> ();
    ArrayList <Edge> edges = new ArrayList <Edge> ();
    ConceptTO pathConceptTO = null;
    Node spreadedNode = new SpreadingNode(formatActivation(conceptTO.getName(),concepts.get(conceptTO.getUri())), conceptTO.getUri());
    Node activatedRoot = new PrintNode(ApplicationResources.getString("initial.node.activated") );
    for (String conceptUri : spreadPathTable.keySet()) {
      PathTO[]path = spreadPathTable.get(conceptUri);
      if(path[path.length-1].getConceptUri().equals(conceptTO.getUri()) && !conceptUri.equals(conceptTO.getUri())){
        Node sonNode = spreadedNode;
        for (int i = path.length-1; i >=0 ; i--) {
          pathConceptTO = ontologyDAO.getConceptTO(path[i].getConceptUri());
          Node pathNode = new PathNode(
              formatActivation(pathConceptTO.getName(),
                  concepts.get(pathConceptTO.getUri())),path[i].getConceptUri());
//          for(String relation:path[i].getRelationsUri()){
//            if(relation == null) relation = "#INITIAL";
//            edges.add(new TextEdge(pathNode,sonNode,""+formatRelation(relation))); 
//          }
          edges.add(new LineEdge(pathNode,sonNode));
          nodes.add(pathNode);
          sonNode = pathNode;
        }
        pathConceptTO = ontologyDAO.getConceptTO(conceptUri);       
        Node activateNode =
          new ActivationNode(
              formatActivation(pathConceptTO.getName(),
                  concepts.get(pathConceptTO.getUri())),
                  pathConceptTO.getUri());
        for(String relation:path[path.length-1].getRelationsUri()){
          if(relation != null)
            edges.add(new TextEdge(activatedRoot,activateNode,formatRelation(relation)))
        }       
        nodes.add(activateNode);
      }//If activated by current spread node
    }
    edges.add(new ArrowEdge(spreadedNode,activatedRoot));
    nodes.add(activatedRoot);
    nodes.add(spreadedNode);
    graph.addElements(nodes, edges);
    return graph;
  }
View Full Code Here

    //return (relations.contains(relationUri))?
      //  relationUri.replaceAll("http://dbpedia.org/property/", ""):"";
  }

  public static DefaultGraph createEmptyGraph() {
    DefaultGraph graph = new DefaultGraph();
    ArrayList <Node> nodes = new ArrayList <Node> ();
    ArrayList <Edge> edges = new ArrayList <Edge> ();
    graph.addElements(nodes, edges);
    return graph;
  }
View Full Code Here

        nodes.add(nodePath);
      }
    }
  }
  public DefaultGraph getSubGraph(Collection <Node> selectedNodes){
    DefaultGraph graph = new DefaultGraph();
    for (Node n : selectedNodes){
      List <Node> nodes = new ArrayList <Node> ();
      List <Edge> edges = new ArrayList <Edge> ();
      nodes.add(n);

      Pair<List <Node>, List<Edge>> p = getParents(n);
      nodes.addAll(p.getFirst());
      edges.addAll(p.getSecond());

      Pair<List <Node>, List<Edge>> c = getDirectChildren(n);
      nodes.addAll(c.getFirst());
      edges.addAll(c.getSecond());

      graph.addElements(nodes, edges);
    }
    return graph;
  }
View Full Code Here

        lensSet.addLens(m_nodeSizelens);
        lensSet.addLens(m_translateLens);
    }
   
    public DefaultGraph createGraph(){
        DefaultGraph graph = new DefaultGraph();
        ArrayList <Node> nodes = new ArrayList <Node> ();
        ArrayList <Edge> edges = new ArrayList <Edge> ();
       
        Node n1 = new NodeType1("Node 1");
        Node sn1 = new NodeType2("Node 2");
        Node sn2 = new NodeType2("Node 3");
        ClusterNode sn3 = new NodeType4("Node 4", 19);
        Node sn4 = new NodeType2("Node 5");
        Node sn5 = new NodeType2("Node 6");
        Node sn6 = new NodeType2("Multi Line\nNode Label");
        Node ssn1 = new NodeType3("Node 7");
        Node ssn2 = new NodeType3("Node 8");
       
        nodes.add(n1);
        nodes.add(sn1);
        nodes.add(sn2);
        nodes.add(sn3);
        nodes.add(sn4);
        nodes.add(sn5);
        nodes.add(sn6);
        nodes.add(ssn1);
        nodes.add(ssn2);
       
        edges.add(new LineEdge(n1, sn1));
        edges.add(new TextEdge(n1, sn2, "edge label"));
        edges.add(new ClusterEdge(n1, sn3, true));
        edges.add(new LoopEdge2(sn3));
        edges.add(new LineEdge(n1, sn4));
        edges.add(new LoopEdge(sn4));
        edges.add(new LineEdge(n1, sn5));
        edges.add(new LoopEdge2(sn5));
        edges.add(new LineEdge(n1, sn6));
        edges.add(new ArrowEdge(sn1, ssn1));
        edges.add(new ArrowEdge(sn1, ssn2));
       
        graph.addElements(nodes, edges);
        return graph;
    }
View Full Code Here

        graph.addElements(nodes, edges);
        return graph;
    }
   
    public DefaultGraph getSubGraph(Collection <Node> selectedNodes){
        DefaultGraph graph = new DefaultGraph();
        for (Node n : selectedNodes){
            List <Node> nodes = new ArrayList <Node> ();
            List <Edge> edges = new ArrayList <Edge> ();
            nodes.add(n);
           
            Pair<List <Node>, List<Edge>> p = getParents(n);
            nodes.addAll(p.getFirst());
            edges.addAll(p.getSecond());
           
            Pair<List <Node>, List<Edge>> c = getDirectChildren(n);
            nodes.addAll(c.getFirst());
            edges.addAll(c.getSecond());
           
            graph.addElements(nodes, edges);
        }
        return graph;
    }
View Full Code Here

TOP

Related Classes of net.sourceforge.jpowergraph.defaults.DefaultGraph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.