-
Notifications
You must be signed in to change notification settings - Fork 1
Conversation
…rst implementation of the lexer
# Conflicts: # core/src/main/java/de/unistuttgart/iaas/amyassist/amy/core/speech/SpeechCommandHandler.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In itself, quite understandable. However, general things could be better described in the class Comments
import java.util.List; | ||
|
||
/** | ||
* AGF lexer implementation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think to improve understanding in general it would be better to make more detailed Java class comments. (Not only in this class)
|
||
/** | ||
* | ||
* the AGF Parser implementation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
import de.unistuttgart.iaas.amyassist.amy.core.natlang.agf.nodes.AGFNode; | ||
|
||
/** | ||
* AGF Parselet interface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
for(int i = 0; i < node.getChilds().size(); i++) { | ||
handleNode(b, node.getChilds().get(i)); | ||
if(i!=node.getChilds().size()-1) { | ||
b.append("|"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe it makes sense to pack this into a method. I think it is to much code for a case statement
for(int i = 0; i < node.getChilds().size(); i++) { | ||
handleNode(b, node.getChilds().get(i)); | ||
if(i!=node.getChilds().size()-1) { | ||
b.append("|"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
added deprecations added NLProcessingManager
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -37,6 +37,7 @@ | |||
* | |||
* @author Leon Kiefer | |||
*/ | |||
@Deprecated | |||
public class NaturalLanguageInterpreterAnnotationReader { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Smell: Add the missing @deprecated Javadoc tag. (squid:MissingDeprecatedCheck)
@@ -38,7 +39,9 @@ | |||
@Target(java.lang.annotation.ElementType.METHOD) | |||
public @interface Grammar { | |||
/** | |||
* @return the grammar | |||
* TODO description |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Smell: Complete the task associated to this TODO comment. (squid:S1135)
@Override | ||
public String process(String naturalLanguageText) { | ||
this.logger.debug("input {}", naturalLanguageText); | ||
NLLexer nlLexer = new NLLexer(naturalLanguageText); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Smell: Remove this useless assignment to local variable "nlLexer". (squid:S1854)
* The keyword | ||
*/ | ||
@Deprecated | ||
public void addRule(String ruleName, String[] keywords, String grammar) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Smell: Add the missing @deprecated Javadoc tag. (squid:MissingDeprecatedCheck)
import de.unistuttgart.iaas.amyassist.amy.core.io.Environment; | ||
import de.unistuttgart.iaas.amyassist.amy.core.natlang.agf.AGFLexer; | ||
import de.unistuttgart.iaas.amyassist.amy.core.natlang.agf.AGFParser; | ||
import de.unistuttgart.iaas.amyassist.amy.core.natlang.agf.AGFToken; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Smell: Remove this unused import 'de.unistuttgart.iaas.amyassist.amy.core.natlang.agf.AGFToken'. (squid:UselessImportCheck)
/** | ||
* contains regex with the corresponding WordTokenType | ||
*/ | ||
Map<String, WordTokenType> regexTokenType = new HashMap<>();{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Smell: Move the contents of this initializer to a standard constructor or to field initializers. (squid:S1171)
.isAnnotationPresent(de.unistuttgart.iaas.amyassist.amy.core.plugin.api.SpeechCommand.class)) { | ||
throw new IllegalArgumentException(); | ||
} | ||
String[] speechKeyword = NLIAnnotationReader.getSpeechKeywords(natuaralLanguageInterpreter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Smell: Remove this useless assignment to local variable "speechKeyword". (squid:S1854)
Object[] params = { input }; | ||
return (String) this.method.invoke(instance, params); | ||
} catch (IllegalAccessException | InvocationTargetException e) { | ||
throw new RuntimeException("Tryed to invoke " + this.method.getName(), e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Smell: Define and throw a dedicated exception instead of using a generic one. (squid:S00112)
@@ -27,7 +27,8 @@ | |||
import java.lang.annotation.Retention; | |||
import java.lang.annotation.RetentionPolicy; | |||
import java.lang.annotation.Target; | |||
|
|||
//TODO move the class in a package in the natlang package |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Smell: Complete the task associated to this TODO comment. (squid:S1135)
@@ -51,14 +51,16 @@ | |||
* @author Leon Kiefer | |||
*/ | |||
@Service | |||
@Deprecated | |||
public class SpeechCommandHandler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Smell: Add the missing @deprecated Javadoc tag. (squid:MissingDeprecatedCheck)
# Conflicts: # core/src/main/java/de/unistuttgart/iaas/amyassist/amy/core/speech/result/handler/SpeechCommandHandler.java # core/src/test/java/de/unistuttgart/iaas/amyassist/amy/core/natlang/TestNLIAnnotationReader.java
cleanup tests moved completeSetup to GrammarObjectsCreator
+ "nine | ten | eleven | twelve | thirteen | fourteen | fifteen | " | ||
+ "sixteen | seventeen | eighteen | nineteen | twenty | thirty | forty | " | ||
+ "fifty | sixty | seventy | eighty | ninety | and )+; \n"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to do this, so the number 'and' is not allowed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's saver for the speech recognition, i could make another rule for "and" but that would be kind of pointless
grammar.append("\n//pre defined rules \n"); | ||
|
||
// pre defined rules | ||
grammar.append("<digit> = (one | two | three | four | five | six | seven |" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are not digits but numers, because of the '+' at the end.
public String addRule(AGFNode node, String ruleName) { | ||
StringBuilder b = new StringBuilder(); | ||
b.append("public <" + ruleName + "> = "); | ||
String rule = handleNode(b, node) + ";\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code duplicate: Use private method publicRule().
try { | ||
return Integer.valueOf(numberInt); | ||
}catch(NumberFormatException e) { | ||
this.logger.error(String.format("number in numbers file in wrong format %s" , numberInt)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logger already has the ability to add parameters into the string.
}catch(NumberFormatException e) { | ||
this.logger.error(String.format("number in numbers file in wrong format %s" , numberInt)); | ||
} | ||
return Integer.MAX_VALUE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this make sense? If not it would be better to just rethrow a IllegalStateException.
* | ||
* @param method | ||
* the method that should be a NLIMethod | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add @throws in JavaDoc.
grammar.append("<number> = (one | two | three | four | five | six | seven |" | ||
+ "nine | ten | eleven | twelve | thirteen | fourteen | fifteen | " | ||
+ "sixteen | seventeen | eighteen | nineteen | twenty | thirty | forty | " | ||
+ "fifty | sixty | seventy | eighty | ninety | and )+; \n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only allow and if there is number before and behind.
Map<String, Integer> result = new HashMap<>(); | ||
String[] stringNmbRep; | ||
|
||
InputStream grammarFile = this.getClass().getResourceAsStream("englishNumbers.natlang"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use getClass().getClassLoader().getResourceAsStream()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it strangely only works without .getClassLoader() now, no idea why
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the ClassLoader have a absolute scope and relative paths don't work
BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) { | ||
|
||
// first line contains all numbers seperated by ',' and ending with ';' | ||
String s = bufferedReader.readLine(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also have one rule in one line and iterate over all lines.
|
||
/** | ||
* | ||
* calls the given method and handles handles possible exceptions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
language.
} | ||
|
||
/** | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove empty line
|
||
private final List<PartialNLI> register = new ArrayList<>(); | ||
|
||
private final List<AGFNode> cachedNodeList = new ArrayList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name is not describing the use very good. "cached" sounds like this list is not necessary, just for speed improvements.
//only allow normal SPACE codepoint 32, U+0020 | ||
case 32: | ||
return this.next(); | ||
default: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong indentation.
|
||
} | ||
} | ||
throw new NoSuchElementException("thrown by AGFLexer"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where it is thrown, is automatically contained in this exception. If no good reason can be stated, use constructor without parameter.
/** | ||
* serial version uid | ||
*/ | ||
private static final long serialVersionUID = 1L; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generate svuid, don't use 1L.
} | ||
|
||
/** | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add method description.
Most stuff is finished. Trees are able to be generated from the content of @grammar annotations (which are now called AGF - Amy Grammar Format - expressions) and checked if valid. The generated trees can also be transformed in valid JSGF rules. Right now i'm working on the NLParser, which categorizes the strings received from the web or speech recognition. The last step will be a NLInterpreter class which returns the right matching grammar.
Feel free to suggest changes.
AGF grammars are specified in the wiki
close #95
fixed #177