blob: 2fb03bb6eb48b7373d7a1e7a1afe067345ef8859 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
package org.grammaticalframework.pgf;
import java.util.Collections;
import java.util.Iterator;
/** A callback for recognizing words that are not in the lexicon.
* For such words the callback returns the expression (MkSymb "<word>").
*/
public class UnknownLiteralCallback implements LiteralCallback {
private Concr concr;
private String sentence;
public UnknownLiteralCallback(Concr concr, String sentence) {
this.concr = concr;
this.sentence = sentence;
}
public CallbackResult match(String ann, int offset) {
if (offset < sentence.length() &&
!Character.isUpperCase(sentence.charAt(offset))) {
int start_offset = offset;
while (offset < sentence.length() &&
!Character.isWhitespace(sentence.charAt(offset))) {
offset++;
}
int end_offset = offset;
String word = sentence.substring(start_offset,end_offset);
if (concr.lookupMorpho(word).size() == 0) {
Expr expr = new Expr("MkSymb", new Expr(word));
return new CallbackResult(new ExprProb(expr, 0), end_offset);
}
}
return null;
}
public Iterator<TokenProb> predict(String ann, String prefix) {
return Collections.<TokenProb>emptyList().iterator();
}
}
|