コード例 #1
0
ファイル: FbFormulasInfo.java プロジェクト: heshizhu/sempre
 /** supports chains only */
 public boolean hasOpposite(Formula formula) {
   LispTree tree = formula.toLispTree();
   if (tree.isLeaf()) {
     String fbProperty =
         FreebaseInfo.isReverseProperty(tree.value) ? tree.value.substring(1) : tree.value;
     return freebaseInfo.fbPropertyHasOpposite(fbProperty);
   } else {
     // Un-reverse everything.
     String binary1 = tree.child(2).child(0).value;
     binary1 = FreebaseInfo.isReverseProperty(binary1) ? binary1.substring(1) : binary1;
     String binary2 = tree.child(2).child(1).child(0).value;
     binary2 = FreebaseInfo.isReverseProperty(binary2) ? binary2.substring(1) : binary2;
     return freebaseInfo.fbPropertyHasOpposite(binary1)
         && freebaseInfo.fbPropertyHasOpposite(binary2);
   }
 }
コード例 #2
0
ファイル: FbFormulasInfo.java プロジェクト: heshizhu/sempre
  public Formula equivalentFormula(LispTree tree) {

    if (tree.isLeaf()) {
      boolean rev = FreebaseInfo.isReverseProperty(tree.value);
      String fbProperty = rev ? tree.value.substring(1) : tree.value;
      String oppositeProperty = freebaseInfo.getOppositeFbProperty(fbProperty);
      return rev
          ? Formulas.newNameFormula(oppositeProperty)
          : Formulas.newNameFormula("!" + oppositeProperty);
    } else {
      String binary1 = tree.child(2).child(0).value;
      binary1 = FreebaseInfo.isReverseProperty(binary1) ? binary1.substring(1) : binary1;
      String binary2 = tree.child(2).child(1).child(0).value;
      binary2 = FreebaseInfo.isReverseProperty(binary2) ? binary2.substring(1) : binary2;
      String oppositeBinary1 = freebaseInfo.getOppositeFbProperty(binary1);
      String oppositeBinary2 = freebaseInfo.getOppositeFbProperty(binary2);
      boolean rev = FreebaseInfo.isReverseProperty(tree.child(2).child(0).value);
      return buildLambdaFormula(oppositeBinary1, oppositeBinary2, !rev);
    }
  }
コード例 #3
0
ファイル: SerializedDumper.java プロジェクト: Ashwaray/sempre
 private void dumpExample(LispTree tree) {
   out.println("(example");
   for (LispTree subtree : tree.children.subList(1, tree.children.size())) {
     if (!subtree.isLeaf() && "derivations".equals(subtree.children.get(0).value)) {
       if (subtree.children.size() == 1) {
         out.println("  (derivations)");
       } else {
         out.println("  (derivations");
         for (LispTree derivation : subtree.children.subList(1, subtree.children.size())) {
           out.write("    ");
           derivation.print(Integer.MAX_VALUE, Integer.MAX_VALUE, out);
           out.write("\n");
         }
         out.println("  )");
       }
     } else {
       out.write("  ");
       subtree.print(Integer.MAX_VALUE, Integer.MAX_VALUE, out);
       out.write("\n");
     }
   }
   out.println(")");
 }
コード例 #4
0
ファイル: FbFormulasInfo.java プロジェクト: heshizhu/sempre
 /** supports chains only */
 public boolean isReversed(Formula formula) {
   LispTree tree = formula.toLispTree();
   if (tree.isLeaf()) return FreebaseInfo.isReverseProperty(tree.value);
   else return FreebaseInfo.isReverseProperty(tree.child(2).child(0).value);
 }