|
@@ -40,9 +40,10 @@ public class EntityProcess {
|
|
|
JSONArray relations = annotation.getJSONArray("R");
|
|
|
|
|
|
List<Lemma> allLemmaList = loadAllLemmaList(entitys);
|
|
|
+ List<String> relationIds = new ArrayList<>();
|
|
|
for (Lemma l : allLemmaList) {
|
|
|
if (entityType.equals(l.getProperty())) {
|
|
|
- findRelationLemma(l, allLemmaList, relations);
|
|
|
+ findRelationLemma(l, allLemmaList, relations, relationIds);
|
|
|
resultLemmaList.add(l);
|
|
|
}
|
|
|
}
|
|
@@ -78,19 +79,35 @@ public class EntityProcess {
|
|
|
* @param allLemmaList
|
|
|
* @param relations
|
|
|
*/
|
|
|
- private void findRelationLemma(Lemma lemma, List<Lemma> allLemmaList, JSONArray relations) {
|
|
|
+ private void findRelationLemma(Lemma lemma, List<Lemma> allLemmaList, JSONArray relations, List<String> relationIds) {
|
|
|
List<Relation> connectEntityIdList = getConnectEntityList(lemma.getId(), relations);
|
|
|
for (Lemma l : allLemmaList) {
|
|
|
for (Relation relation : connectEntityIdList) {
|
|
|
if (l.getId() == relation.getId()) {
|
|
|
l.setRelationName(relation.getRelationName());
|
|
|
- findRelationLemma(l, allLemmaList, relations);
|
|
|
+ if (!hasRelation(l.getId(), lemma.getId(), relationIds)) {
|
|
|
+ findRelationLemma(l, allLemmaList, relations, relationIds);
|
|
|
+ }
|
|
|
lemma.addRelationLemmas(l);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private boolean hasRelation(int a, int b, List<String> relationIds) {
|
|
|
+ String s = "";
|
|
|
+ if (a > b) {
|
|
|
+ s = a + "," + b;
|
|
|
+ } else {
|
|
|
+ s = b + "," + a;
|
|
|
+ }
|
|
|
+ if (relationIds.contains(s)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ relationIds.add(s);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 处理关系抽取输出的json
|
|
|
*
|