Skip to content
This repository has been archived by the owner on Oct 3, 2020. It is now read-only.

Commit

Permalink
working on word system for dates
Browse files Browse the repository at this point in the history
  • Loading branch information
fulton committed Nov 30, 2019
1 parent 5b8467a commit 2a3985d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/main/java/com/andromeda/araserver/Run.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.andromeda.araserver.pages.ApiStart;
import com.andromeda.araserver.store.Main;
import com.andromeda.araserver.util.KeyWord;
import com.andromeda.araserver.util.MsSql;
import com.andromeda.araserver.util.SortWords;
import com.rometools.rome.feed.synd.SyndFeed;
import com.rometools.rome.io.FeedException;
Expand All @@ -16,19 +15,17 @@
import opennlp.tools.parser.ParserFactory;
import opennlp.tools.parser.ParserModel;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;

import java.sql.SQLException;
import java.util.Arrays;
import java.util.Objects;



public class Run extends NanoHTTPD {
KeyWord keyWord;
ParserModel model = null;
Parser parser = null;
ParserModel model;
Parser parser;


//Function to declare port
Expand Down Expand Up @@ -58,7 +55,7 @@ private Run(int port) throws IOException {
parser = ParserFactory.create(model);
keyWord = new KeyWord(is);
System.out.println(" reeeeesut");
System.out.println(new SortWords(keyWord, "weather in portland oregon tomorrow").getTopicsPhrase(parser));
System.out.println(new SortWords(keyWord, "weather in portland oregon in two days").getComplexDate(parser));

}
// Static function, to be run on start.
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/com/andromeda/araserver/util/SortWords.kt
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,64 @@ class SortWords(keyWord: KeyWord, mainVal: String) {
}
return toReturn
}
fun getComplexDate(parse: Parser): ArrayList<WordGraph> {
var toReturn = ArrayList<WordGraph>()

var graph = key.getKeyWords(mainText,parse)?.get(0)
graph?.show()


var working = true
if (graph != null) {
graph.show()

while (working) {
when {
graph?.childCount == 1 -> {
graph = graph.children?.get(0)
}
graph?.childCount == 0 -> {
working = false
}
else -> {
if (graph != null) {
val toTest = sortForComplexDate(graph)
toReturn.addAll(toTest)
}
working = false
}

}
}
} else {
print("null")
println("fail")
}
return toReturn
}
private fun sortForComplexDate(graph: Parse): ArrayList<WordGraph> {
println("start")
var toReturn = ArrayList<WordGraph>()
for (i in graph.children!!) {
print(i.coveredText+ " " + i.type)
if (i.type == "NP" && i.parent.type == "PP" && sorter(i, "CD")) {
toReturn.add(WordGraph(i.coveredText, i.type))
}
if (i.childCount > 0) toReturn.addAll(sortForComplexDate(i))
}
return toReturn
}
private fun sorter(graph: Parse, type:String): Boolean {
var toReturn = false
for (i in graph.children){
if (i.type == type){
toReturn = true
}
else if (i.childCount > 0) toReturn = sorter(graph, type)
}
return toReturn

}


}

0 comments on commit 2a3985d

Please sign in to comment.