edu.cornell.cs.nlp.spf.mr.lambda.FlexibleTypeComparator Java Examples

The following examples show how to use edu.cornell.cs.nlp.spf.mr.lambda.FlexibleTypeComparator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CreateSentenceConstantsFile.java    From spf with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {

		// //////////////////////////////////////////
		// Init logging
		// //////////////////////////////////////////
		Logger.DEFAULT_LOG = new Log(System.err);
		Logger.setSkipPrefix(true);
		LogLevel.setLogLevel(LogLevel.INFO);

		// //////////////////////////////////////////
		// Init lambda calculus system.
		// //////////////////////////////////////////

		try {
			// Init the logical expression type system
			LogicLanguageServices
					.setInstance(new LogicLanguageServices.Builder(
							new TypeRepository(new File(args[1])),
							new FlexibleTypeComparator()).build());
		} catch (final IOException e) {
			throw new RuntimeException(e);
		}

		// //////////////////////////////////////////
		// Print output file.
		// //////////////////////////////////////////

		// Read input data.
		final SingleSentenceCollection data = SingleSentenceCollection.read(new File(
				args[0]));

		for (final SingleSentence sentence : data) {
			System.out.println(sentence.getSample());
			System.out.println(ListUtils.join(
					GetConstantsMultiSet.of(sentence.getLabel()), " "));
			System.out.println();
		}

	}
 
Example #2
Source File: NlpPipeline.java    From UDepLambda with Apache License 2.0 4 votes vote down vote up
public NlpPipeline(Map<String, String> options) throws Exception {
  super(options);
  System.err.println(options);
  this.options = options;

  if (options.containsKey(DEPLAMBDA) && options.get(DEPLAMBDA).equals("true")) {
    System.err.println("Loading DepLambda Model.. ");
    try {
      MutableTypeRepository types =
          new MutableTypeRepository(options.get(DEPLAMBDA_DEFINED_TYPES_FILE));
      System.err.println(String.format("%s=%s", DEPLAMBDA_DEFINED_TYPES_FILE,
          options.get(DEPLAMBDA_DEFINED_TYPES_FILE)));

      LogicLanguageServices.setInstance(new LogicLanguageServices.Builder(
          types, new FlexibleTypeComparator()).closeOntology(false)
          .setNumeralTypeName("i").build());

      TransformationRuleGroups treeTransformationRules;
      treeTransformationRules =
          new TransformationRuleGroups(
              options.get(DEPLAMBDA_TREE_TRANSFORMATIONS_FILE));
      System.err.println(String.format("%s=%s",
          DEPLAMBDA_TREE_TRANSFORMATIONS_FILE,
          options.get(DEPLAMBDA_TREE_TRANSFORMATIONS_FILE)));

      TransformationRuleGroups relationPrioritiesRules =
          new TransformationRuleGroups(
              options.get(DEPLAMBDA_RELATION_PRORITIES_FILE));
      System.err.println(String.format("%s=%s",
          DEPLAMBDA_RELATION_PRORITIES_FILE,
          options.get(DEPLAMBDA_RELATION_PRORITIES_FILE)));

      TransformationRuleGroups lambdaAssignmentRules =
          new TransformationRuleGroups(
              options.get(DEPLAMBDA_LAMBDA_ASSIGNMENT_RULES_FILE));
      System.err.println(String.format("%s=%s",
          DEPLAMBDA_LAMBDA_ASSIGNMENT_RULES_FILE,
          options.get(DEPLAMBDA_LAMBDA_ASSIGNMENT_RULES_FILE)));
      Boolean lexicalizePredicates =
          Boolean.parseBoolean(options.getOrDefault(
              DEPLAMBDA_LEXICALIZE_PREDICATES, "true"));

      Logger logger = null;
      if (options.containsKey(DEPLAMBDA_DEBUG_TO_FILE)
          && !options.get(DEPLAMBDA_DEBUG_TO_FILE).trim().equals("")) {
        logger = Logger.getLogger(getClass());
        PatternLayout layout = new PatternLayout("%r [%t] %-5p: %m%n");
        logger.setLevel(Level.DEBUG);
        logger.setAdditivity(false);
        Appender fileAppender =
            new FileAppender(layout, options.get(DEPLAMBDA_DEBUG_TO_FILE));
        logger.addAppender(fileAppender);
      }

      treeTransformer =
          new TreeTransformerMain(treeTransformationRules,
              relationPrioritiesRules, lambdaAssignmentRules, logger,
              lexicalizePredicates);
      System.err.println("Loaded DepLambda Model.. ");
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
 
Example #3
Source File: ResultPrinter.java    From UDepLambda with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
	 if (args.length == 0 || args.length % 2 != 0) {
	      System.err
	          .println("Specify pipeline arguments, e.g., annotator, languageCode, preprocess.capitalize. See the NlpPipelineTest file.");
	      System.exit(0);
	    }

	    Map<String, String> options = new HashMap<>();
	    for (int i = 0; i < args.length; i += 2) {
	      options.put(args[i], args[i + 1]);
	    }

	 Printer printer = new LogicalExpressionSimpleIndenter.Printer("  ");
	 String defined_types = NlpPipeline.DEPLAMBDA_DEFINED_TYPES_FILE;
	 try {
	  TypeRepository types =
	            new MutableTypeRepository(options.get(defined_types));
	        System.err.println(String.format("%s=%s", defined_types,
	            options.get(defined_types)));

	        LogicLanguageServices.setInstance(new LogicLanguageServices.Builder(
	            types, new FlexibleTypeComparator())
	        		.closeOntology(false)
	        		.setNumeralTypeName("i")
	        	//	.setPrinter(new LogicalExpressionVjIndenter.Printer("  "))
	        		.build());
	 } catch (IOException z) {
		 z.printStackTrace();
	 }
	 String input = read(System.in);
	 JsonParser jsonParser = new JsonParser();
	 JsonObject jsonSentence =
			 jsonParser
			 .parse(input)
			 .getAsJsonObject();
	
	Sentence sentence = new Sentence(jsonSentence);
	 System.out.println("----\nSentence: " + cleanString(""+jsonSentence.get("sentence")));
	 System.out.println("\nDepTree:\n" + TreePrinter.toIndentedString(sentence.getRootNode()));
	 
	JsonPrimitive c = (JsonPrimitive) jsonSentence.get(SentenceKeys.DEPLAMBDA_EXPRESSION);
	String depLambda = cleanString(c.toString());
	
	JsonElement logic = jsonSentence.get(SentenceKeys.DEPENDENCY_LAMBDA);
	
	System.out.println("\nDepLambda Expr:\n " + printer.toString(SimpleLogicalExpressionReader.read(depLambda)));
	System.out.println("\nDepLambda simplified: ");
	printJsonArray((JsonArray) logic);
	
	
	

}
 
Example #4
Source File: RunForestTransformer.java    From UDepLambda with Apache License 2.0 4 votes vote down vote up
@Override
public void run(OptionSet options) {
  try {
    int nthreadsVal = options.valueOf(nthreads);
    String inputFileVal = options.valueOf(inputFile);

    InputStream inputStream = SentenceUtils.getInputStream(inputFileVal);
    MutableTypeRepository types =
        new MutableTypeRepository(options.valueOf(definedTypesFile));

    LogicLanguageServices.setInstance(new LogicLanguageServices.Builder(
        types, new FlexibleTypeComparator()).closeOntology(false)
        .setNumeralTypeName("i").build());

    TransformationRuleGroups treeTransformationRules =
        new TransformationRuleGroups(options.valueOf(treeTransformationsFile));
    TransformationRuleGroups relationPrioritiesRules =
        new TransformationRuleGroups(options.valueOf(relationPrioritiesFile));
    TransformationRuleGroups lambdaAssignmentRules =
        new TransformationRuleGroups(
            options.valueOf(lambdaAssignmentRulesFile));

    Logger logger = null;
    if (!options.valueOf(debugToFile).equals("")) {
      logger = Logger.getLogger(getClass());
      PatternLayout layout = new PatternLayout("%r [%t] %-5p: %m%n");
      logger.setLevel(Level.DEBUG);
      logger.setAdditivity(false);
      Appender fileAppender =
          new FileAppender(layout, options.valueOf(debugToFile));
      logger.addAppender(fileAppender);
    }

    TreeTransformerMain treeTransformer =
        new TreeTransformerMain(treeTransformationRules,
            relationPrioritiesRules, lambdaAssignmentRules, logger,
            options.valueOf(lexicalizePredicates));

    if (options.valueOf(inputTypeIsForest)) {
      ForestTransformerMain forestTransoformer =
          new ForestTransformerMain(treeTransformer);
      forestTransoformer.processStream(inputStream, System.out, nthreadsVal,
          true);
    } else {
      treeTransformer.processStream(inputStream, System.out, nthreadsVal,
          true);
    }
  } catch (IOException | InterruptedException e) {
    e.printStackTrace();
  }
}