예제 #1
0
 @Override
 public HostGraph loadGraph(InputStream in) throws IOException {
   DefaultHostGraph result = new DefaultHostGraph(getGraphName());
   BufferedReader reader = new BufferedReader(new InputStreamReader(in));
   try {
     Algebra<?> intAlgebra = AlgebraFamily.getInstance().getAlgebra(Sort.INT);
     TypeLabel valueLabel = TypeLabel.createBinaryLabel("value");
     for (String nextLine = reader.readLine(); nextLine != null; nextLine = reader.readLine()) {
       String[] fragments = nextLine.split(" ");
       if (fragments[0].equals("n")) {
         HostNode node = addNode(result, fragments[1]);
         HostNode valueNode = result.addNode(intAlgebra, intAlgebra.toValueFromJava(fragments[2]));
         result.addEdge(node, valueLabel, valueNode);
       } else if (fragments[0].equals("e")) {
         HostNode source = addNode(result, fragments[1]);
         HostNode target = addNode(result, fragments[2]);
         result.addEdge(source, LABEL, target);
       }
     }
   } finally {
     reader.close();
   }
   return result;
 }
예제 #2
0
 /** Tests conversion from algebra value to term and back. */
 private void testConversion(Algebra<?> algebra, Object value) {
   assertEquals(value, algebra.toValue(algebra.toTerm(value)));
 }