public class SemanticAnalysis extends Pass
SemanticAnalysis
pass builds useful tables, computes classifier types and other
useful information, and generally checks that things appear only where they are expected. More
specifically, the following data is arranged:
A1 | The global symbol table is built. It stores information about classifier, constraint, and inference declarations as well as symbols local to method bodies. |
A2 | The classifier representation table is built. It stores references to internal representations of source code implementing classifiers indexed by the classifiers' names. |
A3 |
Names for every ClassifierExpression are computed. |
A4 |
Type information is computed for classifiers, InstanceCreationExpression s creating outer
classes, and Name s known to refer to classifiers, the latter two only to support the
semantic checks performed over the various classifier specification syntaxes. |
A5 | Method invocations that are actually classifier invocations are marked as such. |
A6 |
If a sense statement with a single argument appears in a generator, the argument
expression is moved from the value to the
name variable in the SenseStatement object, and the
value variable gets a new Constant representing
"true" if the generator is discrete and "1" if the generator is real. |
A7 |
If there are any for , if , while , or do
statements that contain a single statement in their body, that statement is wrapped in a
Block . |
A8 |
The dependor graph, linking the names of CodeGenerator s with the names of other
CodeGenerator s that depend on them, is built for use by RevisionAnalysis . |
A9 |
The invoked graph, linking the names of CodeGenerator s with the names of other
CodeGenerator s that are invoked by them, is built for use by TranslateToJava . |
A10 | If a method of the unique instance of a learning classifier is invoked using the learning classifier's name, code must be inserted to create an instance of that classifier ahead of time and then to call the method on that instance. |
A11 |
If a LearningClassifierExpression does not have a with clause, the default
learning algorithm is substituted. |
A12 |
Flags are set in each ConstraintEqualityExpression indicating if its subexpressions are
learner invocations. |
A13 |
Name s and every ASTNode that represents a new local scope gets a link to the
symbol table representing its scope. |
A14 |
Argument types in arguments of quantifier expressions are marked as such. |
A15 |
Quantified ConstraintEqualityExpression s, ConstraintInvocation s, and
QuantifiedConstraintExpression s are marked as such. |
A16 |
If a InferenceDeclaration does not have a with clause, the default inference
algorithm is substituted. |
A17 |
When a ClassifierName is not alone on the right hand side of a
ClassifierAssignment , its name is set equal to its
referent . |
A18 |
The ClassifierExpression.cacheIn member variable is set when the containing
ClassifierAssignment had a cached or cachedin modifier. |
A19 |
The ClassifierExpression.comment field of each top level classifier expression is set to
the comment of the containing ClassifierAssignment . |
A20 |
When a with clause is specified with an InstanceCreationExpression as an
argument, LearningClassifierExpression.learnerName is set to the name of the class
instantiated. |
A21 |
The value of ClassifierAssignment.singleExampleCache is propagated from
ClassifierAssignment s to ClassifierExpression s. |
And the following conditions are checked for:
B1 | No named classifier is defined more than once. |
B2 | Classifier and constraint invocations can only contain a single argument. |
B3 | The output type of every classifier expression is checked for appropriateness in its context. |
B4 |
The input type of a ClassifierName is checked for appropriateness in its context. |
B5 |
The InstanceCreationExpression in the from clause of a
LearningClassifierExpression instantiates a Parser . |
B6 |
The InstanceCreationExpression in the with clause of a
LearningClassifierExpression instantiates a Learner . |
B7 |
The Learner specified in a LearningClassifierExpression must have input type
assignable from the learning classifier expression's input type. |
B8 |
Classifiers with feature type discrete , real , or arrays of those may be
invoked as if they were methods in any context. |
B9 |
Any classifier other than one of feature return type mixed% may be invoked as a
method when that invocation is the value argument of a sense statement inside a
generator of the same basic type (discrete or real ). Generators may not
be invoked in any other context. Array producing classifiers may also be invoked as the only
argument of a sense statement inside another array producing classifier of the same
basic type. |
B10 |
sense statements may only appear in classifiers that are generators or that return
arrays. |
B11 |
The expression : expression form of the sense statement may only appear in a
generator. |
B12 |
return statements may not appear in classifiers that are generators or that return
arrays or in constraints. |
B13 |
Every ReferenceType must successfully locate the Java Class object for the
type it refers to. |
B14 |
The only "mixed" classifier return type is mixed% . |
B15 |
A CodedClassifier may not be declared as mixed% . |
B16 |
There can be no more than one with clause in a LearningClassifierExpression .
|
B17 |
There can be no more than one from clause in a LearningClassifierExpression .
|
B18 |
There must be exactly one using clause in a LearningClassifierExpression . |
B19 | Constraint statements may only appear in constraint declarations. |
B20 | Constraint declarations must contain at least one constraint statement. |
B21 | Names in classifier expressions must refer to classifiers. |
B22 |
The name to the left of the parentheses in an InferenceInvocation must refer to an
inference. |
B23 |
The name inside the parentheses of an InferenceInvocation must refer to a discrete
learner. |
B24 |
The input type of the classifier inside the parentheses of an InferenceInvocation is
checked for appropriateness in its context. |
B25 |
The inference of an InferenceInvocation must contain an
InferenceDeclaration.HeadFinder whose input type is the same as the input type of the
InferenceInvocation 's argument learner. |
B26 |
Only constraints can be invoked with the @ operator in a constraint statement. |
B27 |
The left hand side of the normalizedby operator must be the name of a
Learner . |
B28 |
The right hand side of the normalizedby operator must instantiate a
Normalizer . |
B29 |
An InferenceDeclaration must contain at least one head finder method. |
B30 |
An InferenceDeclaration must contain exactly one subjectto clause. |
B31 |
An InferenceDeclaration may contain no more than one with clause. |
B32 |
The InstanceCreationExpression in the with clause of an
InferenceDeclaration instantiates a Inference . |
B33 | An inference may not be invoked anywhere other than classifier expression context. |
B34 |
Constraint expressions are only allowed to appear as part of their own separate expression
statement. (The only other place that the parser will allow them is in the head of a
for loop.) |
B35 |
The value supplied before the rounds keyword in a
LearningClassifierExpression 's from clause must be an integer. |
B36 |
The cachedin and cached keywords can be used to cache the value(s)
produced by classifiers returning either a single feature or an array of features in a member
variable of a user's class or a WeakHashMap respectively. The values of features
produced by generators and conjunctions cannot be cached in this way. |
B37 |
There can be no more than one evaluate clause in a
LearningClassifierExpression . |
B38 | In the body of a coded classifier, a method invocation with no parent object is assumed to be a classifier invocation. As such, that classifier's definition must be accessible in one form or another. |
B39 |
LBJava must be properly configure d to use the selected inference algorithm. |
B40 |
The value supplied after the cval keyword in a LearningClassifierExpression
must be an integer. |
B41 |
The value supplied after preExtract must be a Boolean or one of
("none"|"disk"|"diskZip"|"memory"|"memoryZip"). |
B42 |
The value supplied after progressOutput must be an integer. |
B43 |
The value supplied after the alpha keyword in a LearningClassifierExpression
must be a double. |
B44 |
The input to any classifier must have either type ReferenceType or type ArrayType
. |
B45 |
The alpha keyword should not be used if the cval keyword is not being
used. |
B46 |
The testingMetric keyword should not be used if both the cval and
testFrom keywords are not present. |
B47 |
There can be no more than one cval clause in a LearningClassifierExpression .
|
B48 |
There can be no more than one testingMetric clause in a
LearningClassifierExpression . |
B49 |
There can be no more than one alpha clause in a LearningClassifierExpression
. |
B50 |
The InstanceCreationExpression in the testFrom clause of a
LearningClassifierExpression instantiates a Parser . |
B51 |
There can be no more than one testFrom clause in a
LearningClassifierExpression . |
B52 |
Parameter tuning can only be performed if either a cval clause or
testFrom clause is supplied. |
B53 | A parameter set must include only simple constant expressions. |
B54 | A parameter range must be defined such that the enumerated list of values is finite. |
B55 | A parameter range must be defined with numeric values. |
B56 |
A parameter set must be defined within a LearningClassifierExpression . |
B57 |
There can be no more than one preExtract clause in a
LearningClassifierExpression . |
B58 |
The prune clause must be of the form prune a b x where a
is one of ("global"|"perClass"), b is one of ("count"|"percent"), and x
is numeric. |
B59 | The prune threshold must be an integer when using the 'count' type or a real number in [0,1] when using the 'percent' type. |
B60 | Feature pre-extraction should not be explicitly be explicitly enabled when there is no "from" clause (and thus no parser). |
B61 |
The conjunction of a classifier with itself is not allowed if the classifier has return type
discrete or real . |
B62 |
There can be no more than one encoding clause in a
LearningClassifierExpression . |
RevisionAnalysis
,
Parser
,
Learner
,
Normalizer
,
Inference
Modifier and Type | Field and Description |
---|---|
static HashMap<String,HashSet<String>> |
dependorGraph
The keys of this map are the names of
CodeGenerator s; the values are
HashSet s of names of other locally defined CodeGenerator s that depend on
the CodeGenerator named by the associated key. |
static HashMap<String,HashSet<String>> |
invokedGraph
The keys of this map are the names of
CodeGenerator s; the values are
HashSet s of names of other (not necessarily locally defined)
CodeGenerator s that are invoked within the CodeGenerator named by the
associated key. |
static HashMap<String,ClassifierExpression> |
representationTable
The keys of this map are the names of
Classifier s; the values are ASTNode s
representing the source code implementations of the associated Classifier s. |
ast, canAddErrorsAndWarnings, fatalError, root
Constructor and Description |
---|
SemanticAnalysis()
Default constructor.
|
SemanticAnalysis(AST ast)
Instantiates a pass that runs on an entire
AST . |
Modifier and Type | Method and Description |
---|---|
static void |
addDependor(String dependency,
String dependor)
Adds an edge from dependency to dependor in the
dependorGraph . |
Name |
anonymousClassifier(String lastName)
Creates a new anonymous classifier name.
|
static boolean |
isDependentOn(String c1,
String c2)
Use this method to determine if one
CodeGenerator depends on another either directly or indirectly. |
static void |
printDependorGraph()
Prints the contents of
dependorGraph to
STDOUT in a readable form. |
static void |
printInvokedGraph()
Prints the contents of
invokedGraph to
STDOUT in a readable form. |
void |
run(Argument a)
Runs this pass on all nodes of the indicated type.
|
void |
run(AST ast)
Runs this pass on all nodes of the indicated type.
|
void |
run(AtLeastQuantifierExpression q)
Runs this pass on all nodes of the indicated type.
|
void |
run(AtMostQuantifierExpression q)
Runs this pass on all nodes of the indicated type.
|
void |
run(Block b)
Runs this pass on all nodes of the indicated type.
|
void |
run(ClassifierAssignment ca)
Runs this pass on all nodes of the indicated type.
|
void |
run(ClassifierCastExpression cce)
Runs this pass on all nodes of the indicated type.
|
void |
run(ClassifierName cn)
Runs this pass on all nodes of the indicated type.
|
void |
run(ClassifierReturnType t)
Runs this pass on all nodes of the indicated type.
|
void |
run(CodedClassifier cc)
Runs this pass on all nodes of the indicated type.
|
void |
run(CompositeGenerator cg)
Runs this pass on all nodes of the indicated type.
|
void |
run(Conjunction c)
Runs this pass on all nodes of the indicated type.
|
void |
run(Constant c)
Runs this pass on all nodes of the indicated type.
|
void |
run(ConstraintDeclaration c)
Runs this pass on all nodes of the indicated type.
|
void |
run(ConstraintEqualityExpression e)
Runs this pass on all nodes of the indicated type.
|
void |
run(ConstraintInvocation i)
Runs this pass on all nodes of the indicated type.
|
void |
run(ConstraintStatementExpression e)
Runs this pass on all nodes of the indicated type.
|
void |
run(DeclarationList list)
Runs this pass on all nodes of the indicated type.
|
void |
run(DoStatement s)
Runs this pass on all nodes of the indicated type.
|
void |
run(ExistentialQuantifierExpression q)
Runs this pass on all nodes of the indicated type.
|
void |
run(ForStatement s)
Runs this pass on all nodes of the indicated type.
|
void |
run(IfStatement s)
Runs this pass on all nodes of the indicated type.
|
void |
run(ImportDeclaration decl)
Runs this pass on all nodes of the indicated type.
|
void |
run(InferenceDeclaration.HeadFinder h)
Runs this pass on all nodes of the indicated type.
|
void |
run(InferenceDeclaration.NormalizerDeclaration n)
Runs this pass on all nodes of the indicated type.
|
void |
run(InferenceDeclaration d)
Runs this pass on all nodes of the indicated type.
|
void |
run(InferenceInvocation ii)
Runs this pass on all nodes of the indicated type.
|
void |
run(InstanceCreationExpression ice)
Runs this pass on all nodes of the indicated type.
|
void |
run(LearningClassifierExpression lce)
Runs this pass on all nodes of the indicated type.
|
void |
run(MethodInvocation m)
Runs this pass on all nodes of the indicated type.
|
void |
run(Name n)
Runs this pass on all nodes of the indicated type.
|
void |
run(PackageDeclaration decl)
Runs this pass on all nodes of the indicated type.
|
void |
run(ParameterSet p)
Runs this pass on all nodes of the indicated type.
|
void |
run(ReferenceType t)
Runs this pass on all nodes of the indicated type.
|
void |
run(ReturnStatement s)
Runs this pass on all nodes of the indicated type.
|
void |
run(SenseStatement s)
Runs this pass on all nodes of the indicated type.
|
void |
run(UniversalQuantifierExpression q)
Runs this pass on all nodes of the indicated type.
|
void |
run(VariableDeclaration v)
Runs this pass on all nodes of the indicated type.
|
void |
run(WhileStatement s)
Runs this pass on all nodes of the indicated type.
|
static void |
runAndRestore(AST ast)
Running an instance of this pass overwrites the static member
variables; use this method to run an instance of this pass and then restore the static member
variables to their states before the pass was run.
|
void |
wekaIze(int line,
ClassifierReturnType RT,
Name name)
Called when analyzing the feature types for
use by a WEKA classifier.
|
printErrorsAndWarnings, reportError, reportWarning, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, run, runOnChildren, setRoot
public static HashMap<String,HashSet<String>> dependorGraph
CodeGenerator
s; the values are
HashSet
s of names of other locally defined CodeGenerator
s that depend on
the CodeGenerator
named by the associated key. The dependor graph has an entry for
every CodeGenerator
in the source.public static HashMap<String,HashSet<String>> invokedGraph
CodeGenerator
s; the values are
HashSet
s of names of other (not necessarily locally defined)
CodeGenerator
s that are invoked within the CodeGenerator
named by the
associated key. The invoked graph does not necessarily have an entry for every
CodeGenerator
in the source.public static HashMap<String,ClassifierExpression> representationTable
Classifier
s; the values are ASTNode
s
representing the source code implementations of the associated Classifier
s. This
table has an entry for every Classifier
in the source.public static void runAndRestore(AST ast)
ast
- An abstract syntax tree to run semantic analysis on.public static void addDependor(String dependency, String dependor)
dependorGraph
. If the dependor is null
, no new list item is added, but
the HashSet
associated with the dependency is still created if it didn't already
exist.dependency
- The name of the node depended on.dependor
- The name of the node doing the depending.public static boolean isDependentOn(String c1, String c2)
CodeGenerator
depends on another either directly or indirectly.c1
- One CodeGenerator
.c2
- The other CodeGenerator
.true
iff c1
depends on c2
.public static void printDependorGraph()
dependorGraph
to
STDOUT
in a readable form.public static void printInvokedGraph()
invokedGraph
to
STDOUT
in a readable form.public void wekaIze(int line, ClassifierReturnType RT, Name name)
ClassifierReturnType
to lce.attributeString
.
lce.attributeString
takes the form of a colon-separated list of attribute
specifications, each of which are formated in the following way: "type
_
name
(_value-list
)".
value-list
takes the same format as it would in an lbj source file. i.e.
{"value1","value2",...}
type
can take the values str
(string attributes), nom
(nominal attributes), or num
(numerical attributes).
The first attribute in this string is, by convention, considered to be the class attribute.
public Name anonymousClassifier(String lastName)
lastName
- The last part of the classifier's name as determined by its parent's name.public void run(AST ast)
public void run(PackageDeclaration decl)
public void run(ImportDeclaration decl)
public void run(DeclarationList list)
public void run(ClassifierAssignment ca)
public void run(ClassifierCastExpression cce)
public void run(ClassifierName cn)
public void run(CodedClassifier cc)
public void run(CompositeGenerator cg)
public void run(Conjunction c)
public void run(InferenceInvocation ii)
public void run(LearningClassifierExpression lce)
public void run(ParameterSet p)
public void run(Block b)
public void run(MethodInvocation m)
public void run(InstanceCreationExpression ice)
public void run(Name n)
public void run(ForStatement s)
public void run(IfStatement s)
public void run(ReturnStatement s)
public void run(SenseStatement s)
public void run(WhileStatement s)
public void run(DoStatement s)
public void run(VariableDeclaration v)
public void run(Argument a)
public void run(Constant c)
public void run(ReferenceType t)
public void run(ClassifierReturnType t)
public void run(ConstraintDeclaration c)
public void run(ConstraintStatementExpression e)
public void run(UniversalQuantifierExpression q)
public void run(ExistentialQuantifierExpression q)
public void run(AtLeastQuantifierExpression q)
public void run(AtMostQuantifierExpression q)
public void run(ConstraintInvocation i)
public void run(ConstraintEqualityExpression e)
public void run(InferenceDeclaration d)
public void run(InferenceDeclaration.HeadFinder h)
public void run(InferenceDeclaration.NormalizerDeclaration n)
Copyright © 2016. All rights reserved.