1   package ixa.kaflib;
2   
3   import org.eclipse.rdf4j.query.algebra.Str;
4   
5   import java.util.ArrayList;
6   import java.util.HashMap;
7   import java.util.HashSet;
8   
9   /**
10   * Linked Entity in the text.
11   */
12  public class LinkedEntity {
13  
14  	/**
15  	 * LinkedEntity's ID (required)
16  	 */
17  	private String linkedEntityId;
18  
19  	/**
20  	 * LinedEntity's properties
21  	 */
22  	private String resource;
23  	private String reference;
24  	private double confidence;
25  	private Boolean spotted;
26  
27  	private HashMap<String, HashSet<String>> types = new HashMap<>();
28  
29  	/**
30  	 * Mentions to the same entity (at least one required)
31  	 */
32  	private Span<WF> mentions;
33  
34  	LinkedEntity(String linkedEntityId) {
35  		this.linkedEntityId = linkedEntityId;
36  		this.mentions = new Span<WF>();
37  	}
38  
39  	LinkedEntity(String linkedEntityId, Span<WF> mentions) {
40  		if (mentions.size() < 1) {
41  			throw new IllegalStateException("LinkedEntity must contain at least one reference span");
42  		}
43  		this.linkedEntityId = linkedEntityId;
44  		this.mentions = mentions;
45  	}
46  
47  	LinkedEntity(LinkedEntity linkedEntity, HashMap<String, WF> WFs) {
48  		this.linkedEntityId = linkedEntity.linkedEntityId;
49  		this.resource = linkedEntity.resource;
50  		this.reference = linkedEntity.reference;
51  		this.confidence = linkedEntity.confidence;
52  
53  		String id = linkedEntity.getId();
54  		this.mentions = linkedEntity.getWFs();
55  	}
56  
57  	public String getResource() {
58  		return resource;
59  	}
60  
61  	public void setResource(String resource) {
62  		this.resource = resource;
63  	}
64  
65  	public String getReference() {
66  		return reference;
67  	}
68  
69  	public void setReference(String reference) {
70  		this.reference = reference;
71  	}
72  
73  	public double getConfidence() {
74  		return confidence;
75  	}
76  
77  	public void setConfidence(double confidence) {
78  		this.confidence = confidence;
79  	}
80  
81  	public String getId() {
82  		return linkedEntityId;
83  	}
84  
85  	void setId(String id) {
86  		this.linkedEntityId = id;
87  	}
88  
89  	public String getSpanStr() {
90  		String str = "";
91  		for (WF wf : mentions.getTargets()) {
92  			if (!str.isEmpty()) {
93  				str += " ";
94  			}
95  			str += wf.getForm();
96  		}
97  		return str;
98  	}
99  
100 	public void addType(String category, String type) {
101 		if (types.get(category) == null) {
102 			types.put(category, new HashSet<>());
103 		}
104 		types.get(category).add(type);
105 	}
106 
107 	public HashMap<String, HashSet<String>> getTypes() {
108 		return types;
109 	}
110 
111 	public void setTypes(HashMap<String, HashSet<String>> types) {
112 		this.types = types;
113 	}
114 
115 	public Boolean isSpotted() {
116 		return spotted;
117 	}
118 
119 	public void setSpotted(Boolean spotted) {
120 		this.spotted = spotted;
121 	}
122 
123 	/**
124 	 * Returns the term targets of the first span. When targets of other spans are needed getReferences() method should be used.
125 	 */
126 	public Span<WF> getWFs() {
127 		return mentions;
128 //		if (this.mentions.size() > 0) {
129 //			return this.mentions.get(0).getTargets();
130 //		}
131 //		else {
132 //			return null;
133 //		}
134 	}
135 
136 }