コード例 #1
0
ファイル: Graph.java プロジェクト: midiablo/CoarseWordNet
 protected void store(CharSequence basename) throws java.io.IOException {
   BVGraph.store(graph, basename + ArcLabelledImmutableGraph.UNDERLYINGGRAPH_SUFFIX);
   BitStreamArcLabelledImmutableGraph.store(
       graph, basename, basename + ArcLabelledImmutableGraph.UNDERLYINGGRAPH_SUFFIX);
   graph = BitStreamArcLabelledImmutableGraph.loadSequential(basename);
   BVGraph.store(
       reverse, basename + ".reverse" + ArcLabelledImmutableGraph.UNDERLYINGGRAPH_SUFFIX);
   BitStreamArcLabelledImmutableGraph.store(
       reverse,
       basename + ".reverse",
       basename + ".reverse" + ArcLabelledImmutableGraph.UNDERLYINGGRAPH_SUFFIX);
   reverse = BitStreamArcLabelledImmutableGraph.loadSequential(basename + ".reverse");
 }
コード例 #2
0
ファイル: Graph.java プロジェクト: midiablo/CoarseWordNet
 public Graph(BVGraph graph, String[] names) {
   org.apache.log4j.Logger logger =
       org.apache.log4j.Logger.getLogger("it.unimi.dsi.webgraph.ImmutableGraph");
   logger.setLevel(org.apache.log4j.Level.FATAL);
   if (names.length != graph.numNodes())
     throw new Error("Problem with the list of names for the nodes in the graph.");
   try {
     File auxFile = File.createTempFile("graph-maps-" + System.currentTimeMillis(), "aux");
     auxFile.deleteOnExit();
     RecordManager recMan = RecordManagerFactory.createRecordManager(auxFile.getAbsolutePath());
     nodes = recMan.hashMap("nodes");
     nodesReverse = recMan.hashMap("nodesReverse");
   } catch (IOException ex) {
     throw new Error(ex);
   }
   nodes.clear();
   nodesReverse.clear();
   Constructor[] cons = WeightedArc.class.getDeclaredConstructors();
   for (int i = 0; i < cons.length; i++) cons[i].setAccessible(true);
   Integer aux1 = null;
   WeightedArcSet list = new WeightedArcSet();
   it.unimi.dsi.webgraph.NodeIterator it = graph.nodeIterator();
   while ((aux1 = it.nextInt()) != null) {
     LazyIntIterator suc = it.successors();
     Integer aux2 = null;
     while ((aux2 = suc.nextInt()) != null && aux2 >= 0 && (aux2 < graph.numNodes()))
       try {
         if (commit++ % COMMIT_SIZE == 0) {
           list.commit();
         }
         list.add((WeightedArc) cons[0].newInstance(aux1, aux2, (float) 1.0));
       } catch (Exception ex) {
         throw new Error(ex);
       }
   }
   this.graph = new WeightedBVGraph(list.toArray(new WeightedArc[0]));
   list = new WeightedArcSet();
   it = graph.nodeIterator();
   while ((aux1 = it.nextInt()) != null) {
     LazyIntIterator suc = it.successors();
     Integer aux2 = null;
     while ((aux2 = suc.nextInt()) != null && aux2 >= 0 && (aux2 < graph.numNodes()))
       try {
         if (commit++ % COMMIT_SIZE == 0) {
           commit();
           list.commit();
         }
         list.add((WeightedArc) cons[0].newInstance(aux2, aux1, (float) 1.0));
         this.nodes.put(aux1, names[aux1]);
         this.nodes.put(aux2, names[aux2]);
         this.nodesReverse.put(names[aux1], aux1);
         this.nodesReverse.put(names[aux2], aux2);
       } catch (Exception ex) {
         throw new Error(ex);
       }
   }
   this.reverse = new WeightedBVGraph(list.toArray(new WeightedArc[0]));
   numArcs = list.size();
   iterator = nodeIterator();
   try {
     File auxFile = File.createTempFile("graph" + System.currentTimeMillis(), "aux");
     auxFile.deleteOnExit();
     String basename = auxFile.getAbsolutePath();
     store(basename);
   } catch (IOException ex) {
     throw new Error(ex);
   }
   commit();
 }