Skip to content
Snippets Groups Projects

Object agg

1 file
+ 80
2
Compare changes
  • Side-by-side
  • Inline
package org.aksw.owl2nl;
import edu.stanford.nlp.ling.CoreLabel;
import edu.stanford.nlp.ling.IndexedWord;
import edu.stanford.nlp.pipeline.CoreDocument;
import edu.stanford.nlp.pipeline.CoreSentence;
@@ -17,8 +18,8 @@ public class OptimizerDepParse {
try {
if (text == null || text == "") return text;
//text="something that a man that sings rock and that a man that sings jazz or a man that sings karaoke or a man that sings metal";
//text="something that a man that sings rock and that a man that sings rock or a man that sings karaoke or a man that sings metal";
text="something that a man that knows angular and that a woman that knows angular";
StanfordCoreNLP stanfordCoreNLP = Pipeline.getPipeline();
CoreDocument coreDocument = new CoreDocument(text);
SemanticGraphFormatter sgf = new SemanticGraphFormatter(1, 1, false, false, false, false, false);
@@ -50,6 +51,35 @@ public class OptimizerDepParse {
List<IndexedWord> verbList = new ArrayList();
List<Integer> verbIndex = new ArrayList();
List<IndexedWord> objectList = new ArrayList();
List<Integer> objectIndex = new ArrayList();
//object list
int objectcounter=0;
for (int i = 0; i < nodeList.size(); i++) {
String object="";
if ((nodeList.get(i).tag()).equals("VBZ")) {
objectcounter = i+1;
for(int j=i+1; j<nodeList.size(); j++){
if ((nodeList.get(j).tag()).equals("CC") || (nodeList.get(j).tag()).equals(".")){
i++;
break;
}
else{
object=object+nodeList.get(j)+" ";
i++;
}
};
}
if(object=="" || object=="."){
}
else{
objectList.add(new IndexedWord(CoreLabel.wordFromString(object)));
objectIndex.add(objectcounter);
}
}
/*loading list*/
for (int i = 0; i < nodeList.size(); i++) {
@@ -72,12 +102,18 @@ public class OptimizerDepParse {
}
boolean subjectsChecker=false;
boolean verbsChecker=false;
boolean objectChecker=false;
boolean aggregated=false;
//System.out.println("Objects");
//System.out.println(objectList);
//boolean objectsame=checkAllObjectsSame(objectList);
//System.out.println("today hello"+objectsame);
String finalText="";
List<IndexedWord> finalTextList=new ArrayList<>();
if(combinedCcCommaList.size()>=1) {
subjectsChecker = checkAllSubjectsSame(nodeList, verbIndex, combinedCcCommaIndex);
verbsChecker = checkAllVerbsSame(verbList);
objectChecker=checkAllObjectsSame(objectList);
}
if(combinedCcCommaList.size()>=1 && verbList.size()==combinedCcCommaList.size()+1) {
@@ -88,6 +124,13 @@ public class OptimizerDepParse {
finalTextList = aggregateByVerbs(nodeList, verbIndex, combinedCcCommaIndex);
}
}
else{
//for different subject same verbs and same objects
if(verbsChecker && objectChecker){
finalTextList=aggregateByObjects(nodeList,verbIndex,combinedCcCommaIndex);
aggregated=true;
}
}
}
if(aggregated){
@@ -133,6 +176,16 @@ public class OptimizerDepParse {
return true;
}
public static boolean checkAllObjectsSame(List<IndexedWord> objects){
for(int j=1;j<objects.size();j++){
if(!((objects.get(0).value()).equals(objects.get(j).value()))){
//not same objects
return false;
}
}
return true;
}
//Method to check whether all subjects in the sentence are same or not
public static boolean checkAllSubjectsSame(List<IndexedWord> nodeList,List<Integer> verbIndex,List<Integer> combinedCcCommaIndex){
@@ -237,5 +290,30 @@ public class OptimizerDepParse {
return aggregatedList;
}
//object aggregation: different subject+same verbs+same object
public static List<IndexedWord> aggregateByObjects(List<IndexedWord> nodeList, List<Integer> verbIndex, List<Integer> combinedCcCommaIndex) {
List<IndexedWord> aggregatedList=new ArrayList();
// removing verbs and object from the while list
for(int i=0;i<verbIndex.size();i++){
if(i==0){
for(int j=0;j<verbIndex.get(i);j++){
aggregatedList.add(nodeList.get(j));
}
}
else if(i==verbIndex.size()-1){
for (int j=combinedCcCommaIndex.get(i-1);j<nodeList.size();j++){
aggregatedList.add(nodeList.get(j));
}
}
else{
for(int j=combinedCcCommaIndex.get(i-1); j<verbIndex.get(i); j++){
aggregatedList.add(nodeList.get(j));
}
}
}
return aggregatedList;
}
}
Loading