Beispiel #1
0
 private String getType1Desc(FormulaGenerationInfo fgInfo) {
   if (fgInfo.isUnary) {
     return fgInfo.uInfo.getRepresentativeDescrption();
   }
   if (fgInfo.bInfo.expectedType1.equals(FreebaseInfo.DATE)) return "date";
   if (fgInfo.bInfo.expectedType1.equals(FreebaseInfo.FLOAT)) return "number";
   if (fgInfo.bInfo.expectedType1.equals(FreebaseInfo.INT)) return "number";
   if (fgInfo.bInfo.expectedType1.equals(FreebaseInfo.BOOLEAN)) return "";
   if (fgInfo.bInfo.expectedType1.equals(FreebaseInfo.TEXT)) return "description";
   Formula type1Formula =
       new JoinFormula(
           FreebaseInfo.TYPE, new ValueFormula<Value>(new NameValue(fgInfo.bInfo.expectedType1)));
   try {
     if (fbFormulasInfo.getUnaryInfo(type1Formula) == null) {
       LogInfo.logs("No unary info for=%s", type1Formula);
       return null;
     }
     return fbFormulasInfo.getUnaryInfo(type1Formula).getRepresentativeDescrption();
   } catch (NullPointerException e) {
     if (type1Formula.toString().equals("(fb:type.object.type fb:type.object)")) return "thing";
     else {
       LogInfo.logs(
           "Binfo exType1=%s, exType2=%s", fgInfo.bInfo.expectedType1, fgInfo.bInfo.expectedType2);
       throw new RuntimeException(e);
     }
   }
 }
Beispiel #2
0
 public boolean isEquivalent(Formula formula1, Formula formula2) {
   if (formula1.equals(formula2)) return true;
   if (hasOpposite(formula1)) {
     Formula equiv1 = equivalentFormula(formula1);
     return equiv1.equals(formula2);
   }
   return false;
 }
Beispiel #3
0
 private boolean isLegalCvt(Formula inner, Formula outer) {
   if (FreebaseInfo.isReverseProperty(inner.toString())
       && !FreebaseInfo.isReverseProperty(outer.toString())) return false;
   if (!FreebaseInfo.isReverseProperty(inner.toString())
       && FreebaseInfo.isReverseProperty(outer.toString())) return false;
   // if (isEquivalent(reverseFormula(outer), inner)) //don't expand if reverse is equivalent
   // return false;
   return true;
 }
Beispiel #4
0
 public String toString() {
   return formula.toString()
       + "\t"
       + popularity
       + "\t"
       + expectedType1
       + "\t"
       + expectedType2
       + "\t"
       + unitId
       + "\t"
       + unitDesc
       + "\t"
       + Joiner.on("###").join(descriptions);
 }
Beispiel #5
0
 /** 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);
   }
 }
Beispiel #6
0
  public Formula equivalentFormula(Formula formula) {

    LispTree tree = formula.toLispTree();
    return equivalentFormula(tree);
  }
Beispiel #7
0
 /** 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);
 }