use of jcog.io.Twokenize.Span in project narchy by automenta.
the class Twenglish method parseSentence.
@NotNull
protected Collection<TaskBuilder> parseSentence(String source, @NotNull NAR n, @NotNull List<Span> s) {
LinkedList<Term> t = new LinkedList();
Span last = null;
for (Span c : s) {
t.add(spanToTerm(c));
last = c;
}
if (t.isEmpty())
return Collections.emptyList();
// Atomic sentenceType = FRAGMENT;
// if ((last!=null) && ("punct".equals(last.pattern))) {
// switch (last.content) {
// case ".": sentenceType = JUDGMENT; break;
// case "?": sentenceType = QUESTION; break;
// //case "@": sentenceType = QUEST; break;
// case "!": sentenceType = GOAL; break;
// }
// }
// if (!"words".equals(sentenceType.toString()))
// t.removeLast(); //remove the punctuation, it will be redundant
List<TaskBuilder> tt = new ArrayList();
// 1. add the logical structure of the sequence of terms
if (inputProduct) {
Term tokens = $.p(t.toArray(new Term[t.size()]));
// Term q =
// $.image(2,
// $.the(source),
// sentenceType,
// tokens
// )
Term q = $.func("hear", Atomic.the(source), tokens);
// n.task(q + ". %0.95|0.95%");
TaskBuilder newtask = new TaskBuilder(q, BELIEF, 1f, n).present(n);
// TODO non-string construct
tt.add(newtask);
}
return tt;
}
use of jcog.io.Twokenize.Span in project narchy by automenta.
the class Twenglish method parse.
/**
* returns a list of all tasks that it was able to parse for the input
*/
@NotNull
public List<TaskBuilder> parse(String source, @NotNull NAR n, String s) {
List<TaskBuilder> results = $.newArrayList();
List<Span> tokens = Twokenize.twokenize(s);
List<List<Span>> sentences = $.newArrayList();
List<Span> currentSentence = $.newArrayList(tokens.size());
for (Span p : tokens) {
currentSentence.add(p);
if ("punct".equals(p.pattern)) {
switch(p.content) {
case ".":
case "?":
case "!":
if (!currentSentence.isEmpty()) {
sentences.add(currentSentence);
currentSentence = $.newArrayList();
break;
}
}
}
}
if (!currentSentence.isEmpty())
sentences.add(currentSentence);
for (List<Span> x : sentences) {
Collection<TaskBuilder> ss = parseSentence(source, n, x);
if (ss != null)
results.addAll(ss);
}
if (!results.isEmpty()) {
// if (!languageBooted) {
//
//
// results.add(0, n.task(new StringBuilder(
// "<{word,pronoun,qpronoun,prepos,conjunc} -]- symbol>.").toString()));
// results.add(0, n.task(new StringBuilder(
// "$0.90;0.90$ <(*,<$a-->[$d]>,<is-->[verb]>,<$b-->[$d]>) =/> <$a <-> $b>>.").toString()));
//
// languageBooted = true;
// }
}
return results;
}
Aggregations