Package edu.stanford.nlp.sempre

Examples of edu.stanford.nlp.sempre.Formula


    List<EntityLexicalEntry> res = new LinkedList<EntityLexicalEntry>();
    textDesc = textDesc.replaceAll("\\?", "\\\\?").toLowerCase();
    List<Document> docs = searcher.searchDocs(textDesc);
    for (Document doc : docs) {

      Formula formula = Formula.fromString(doc.get(FbIndexField.ID.fieldName()));
      String[] fbDescriptions = new String[]{doc.get(FbIndexField.TEXT.fieldName())};
      String typesDesc = doc.get(FbIndexField.TYPES.fieldName());

      Set<String> types = new HashSet<String>();
      if (typesDesc != null) {
View Full Code Here


      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);
      }
View Full Code Here

      i++;
      if (i == 1)
        continue;
      String[] tokens = line.split("\t");
      String nl = tokens[0]; //it is already stemmed and normalized
      Formula formula = Formula.fromString(tokens[1]);
      Map<String,Double> features = new TreeMap<String, Double>();
      features.put(INTERSECTION, Double.parseDouble(tokens[2]));
      features.put(NL_SIZE, Double.parseDouble(tokens[3]));
      features.put(FB_SIZE, Double.parseDouble(tokens[4]));
View Full Code Here

    int i = 0;
    for (String line : IOUtils.readLines(stringFile)) {
     
      String[] tokens = line.split("\t");
      String nl = tokens[3].toLowerCase();
      Formula formula = Formula.fromString(tokens[1]);
      if(fbFormulasInfo.getUnaryInfo(formula)==null) {
          LogInfo.log("Skipping on formula since info is missing from schema: " + formula);
      }
      else {
        UnaryFormulaInfo uInfo = fbFormulasInfo.getUnaryInfo(formula);

        Map<Pair<Formula, String>, UnaryLexicalEntry> formulaToAlignmentInfoMap = res.get(nl);
        if (formulaToAlignmentInfoMap == null) {
          formulaToAlignmentInfoMap = new HashMap<Pair<Formula,String>, UnaryLexicalEntry>();
          res.put(nl, formulaToAlignmentInfoMap);
        }
        UnaryLexicalEntry uEntry =
            formulaToAlignmentInfoMap.get(new Pair<Formula,String>(formula,EntrySource.STRING_MATCH.toString()));
        if (uEntry == null) {
         
          uEntry = new UnaryLexicalEntry(nl, nl, new TreeSet<String>(uInfo.descriptions), formula, EntrySource.STRING_MATCH, uInfo.popularity,
              new TreeMap<String,Double>(), uInfo.types);
          formulaToAlignmentInfoMap.put(new Pair<Formula, String>(formula, EntrySource.STRING_MATCH.toString()), uEntry);
        }
        i++;
        if (i % 1000 == 0)
          LogInfo.log("Adding mapping from nl: " + nl + " to formula " + formula.toString())
      }
    }
    return res;
  }
View Full Code Here

      if (tree.child(0).value.equals("entity")) {

        String textDescription = tree.child(i++).value;
        String normalizedTextDesc = tree.child(i++).value;
        Set<String> fbDescriptions = setFromLispTree(tree.child(i++));
        Formula formula = Formula.fromString(tree.child(i++).value);
        EntrySource source = EntrySource.parseSourceDesc(tree.child(i++).value);
        double popularity = Double.parseDouble(tree.child(i++).value);
        double distance = Double.parseDouble(tree.child(i++).value);
        Set<String> types = setFromLispTree(tree.child(i++));
        Counter<String> tokenEditDistanceFeatures = counterFromLispTree(tree.child(i++));

        return new LexicalEntry.EntityLexicalEntry(
            textDescription, normalizedTextDesc, fbDescriptions, formula,
            source, popularity, distance, types, tokenEditDistanceFeatures);
      } else if (tree.child(0).value.equals("unary")) {
        String textDescription = tree.child(i++).value;
        String normalizedTextDesc = tree.child(i++).value;
        Set<String> fbDescriptions = setFromLispTree(tree.child(i++));
        Formula formula = Formula.fromString(tree.child(i++).value);
        EntrySource source = EntrySource.parseSourceDesc(tree.child(i++).value);
        double popularity = Double.parseDouble(tree.child(i++).value);
        Double.parseDouble(tree.child(i++).value);
        Map<String,Double> alignmentScores = featureMapFromLispTree(tree.child(i++));
        Set<String> types = setFromLispTree(tree.child(i++));
        return new LexicalEntry.UnaryLexicalEntry(
            textDescription, normalizedTextDesc, fbDescriptions, formula, source,
            popularity, alignmentScores, types);
      } else if (tree.child(0).value.equals("binary")) {
        String textDescription = tree.child(i++).value;
        String normalizedTextDesc = tree.child(i++).value;
        Set<String> fbDescriptions = setFromLispTree(tree.child(i++));
        Formula formula = Formula.fromString(tree.child(i++).value);
        EntrySource source = EntrySource.parseSourceDesc(tree.child(i++).value);
        double popularity = Double.parseDouble(tree.child(i++).value);
        Double.parseDouble(tree.child(i++).value); //this is computed in the constructor so need not save it
        String expectedType1 = tree.child(i++).value;
        String expectedType2 = tree.child(i++).value;
View Full Code Here

TOP

Related Classes of edu.stanford.nlp.sempre.Formula

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.