Main { public static void runSemanticAnalysis(AST ast) { new SemanticAnalysis(ast).run(); Pass.printErrorsAndWarnings(); if (generatedSourceDirectory != null) { if (AST.globalSymbolTable.getPackage().length() != 0) generatedSourceDirectory += File.separator + AST.globalSymbolTable.getPackage().replace('.', File.separatorChar); } else if (sourceDirectory != null) generatedSourceDirectory = sourceDirectory; if (classPackageDirectory != null && AST.globalSymbolTable.getPackage().length() != 0) classDirectory = classPackageDirectory + File.separator + AST.globalSymbolTable.getPackage().replace('.', File.separatorChar); else classDirectory = classPackageDirectory; }  static void main(String[] args); static void runSemanticAnalysis(AST ast); static void PrintUsage(); static boolean clean; static boolean concurrentTraining; static boolean warningsDisabled; static boolean printSymbols; static String sourceDirectory; static String sourceFilename; static String sourceFileBase; static String javacArguments; static HashSet<String> fileNames; static String classDirectory; static String classPackageDirectory; static String classPath; static String sourcePath; static String generatedSourceDirectory; }
@Test public void testOneFeature() throws Exception { String input = generateLBJavaScript("OneFeatLearner", "testFeature1", "import edu.illinois.cs.cogcomp.lbjava.features.PredefinedFeature;"); Yylex scanner = new Yylex(new ByteArrayInputStream(input.getBytes())); AST ast = (AST) new parser(scanner).parse().value; Main.runSemanticAnalysis(ast); assertEquals(3, SemanticAnalysis.dependorGraph.size()); assertEquals(1, ast.declarations.size()); ASTNode[] astNodes = ast.declarations.iterator().next().iterator().children; assertEquals(3, astNodes.length); assertTrue(astNodes[0] instanceof ClassifierReturnType); assertEquals("discrete", astNodes[0].toString()); assertTrue(astNodes[2] instanceof LearningClassifierExpression); LearningClassifierExpression lce = (LearningClassifierExpression) astNodes[2]; assertEquals("testFeature1", lce.extractor.getName()); assertTrue(((ClassifierName) lce.extractor).isField); assertEquals("PredefinedFeature", AST.globalSymbolTable.classForName(lce.extractor.getName()).getSimpleName()); new RevisionAnalysis(ast).run(ast); new ClassifierCSE(ast).run(ast); new TranslateToJava(ast).run(ast); new Train(ast, 0).run(ast); }
@Test public void testTwoFeatures() throws Exception { String input = generateLBJavaScript("TwoFeatLearner", "testFeature1, testFeature2", "import edu.illinois.cs.cogcomp.lbjava.features.PredefinedFeature;"); Yylex scanner = new Yylex(new ByteArrayInputStream(input.getBytes())); AST ast = (AST) new parser(scanner).parse().value; Main.runSemanticAnalysis(ast); assertEquals(5, SemanticAnalysis.dependorGraph.size()); assertEquals(1, ast.declarations.size()); ASTNode[] astNodes = ast.declarations.iterator().next().iterator().children; assertEquals(3, astNodes.length); assertTrue(astNodes[0] instanceof ClassifierReturnType); assertEquals("discrete", astNodes[0].toString()); assertTrue(astNodes[2] instanceof LearningClassifierExpression); LearningClassifierExpression lce = (LearningClassifierExpression) astNodes[2]; assertEquals("TwoFeatLearner$$1", lce.extractor.getName()); ClassifierExpressionList components = ((CompositeGenerator) lce.extractor).components; assertEquals(2, components.size()); ClassifierName component1 = (ClassifierName) components.iterator().next(); assertTrue(component1.isField); assertEquals("PredefinedFeature", AST.globalSymbolTable.classForName(component1.getName()) .getSimpleName()); new RevisionAnalysis(ast).run(ast); new ClassifierCSE(ast).run(ast); new TranslateToJava(ast).run(ast); new Train(ast, 0).run(ast); }
@Test public void testPackageFeature() throws Exception { String input = generateLBJavaScript("PackageFeatLearner", "testFeature1", "import edu.illinois.cs.cogcomp.lbjava.features.*;"); Yylex scanner = new Yylex(new ByteArrayInputStream(input.getBytes())); AST ast = (AST) new parser(scanner).parse().value; Main.runSemanticAnalysis(ast); assertEquals(3, SemanticAnalysis.dependorGraph.size()); assertEquals(1, ast.declarations.size()); ASTNode[] astNodes = ast.declarations.iterator().next().iterator().children; assertEquals(3, astNodes.length); assertTrue(astNodes[0] instanceof ClassifierReturnType); assertEquals("discrete", astNodes[0].toString()); assertTrue(astNodes[2] instanceof LearningClassifierExpression); LearningClassifierExpression lce = (LearningClassifierExpression) astNodes[2]; assertEquals("testFeature1", lce.extractor.getName()); assertTrue(((ClassifierName) lce.extractor).isField); assertEquals("PredefinedFeature", AST.globalSymbolTable.classForName(lce.extractor.getName()).getSimpleName()); new RevisionAnalysis(ast).run(ast); new ClassifierCSE(ast).run(ast); new TranslateToJava(ast).run(ast); new Train(ast, 0).run(ast); }