8 package cz.vutbr.fit.knot.annotations.entity.attribute;
12 import java.util.ArrayList;
13 import java.util.Arrays;
14 import java.util.Collections;
15 import java.util.Iterator;
16 import java.util.List;
18 import javax.persistence.DiscriminatorValue;
19 import javax.persistence.Entity;
20 import javax.persistence.NamedQueries;
21 import javax.persistence.NamedQuery;
35 @DiscriminatorValue(
"Entity")
37 @NamedQuery(name =
"Attribute.findByEntityName", query =
"SELECT a FROM Attribute a WHERE a.stringValue = :name"),
38 @NamedQuery(name =
"Attribute.findByEntityType", query =
"SELECT a FROM Attribute a WHERE a.entityType = :type"),
39 @NamedQuery(name =
"Attribute.findByEntityUri", query =
"SELECT a FROM Attribute a WHERE a.uri = :uri")
47 this.simpleType =
"Entity";
59 public EntityAttribute(String name, String type, String URI, String visualRepresentation, String description){
60 this.entityType = type;
61 this.stringValue = name;
62 this.simpleType =
"Entity";
64 this.entityVisualURI = visualRepresentation;
65 this.textValue = description;
75 return this.entityAdditionalAttributes;
84 this.entityAdditionalAttributes = EntityAdditionalAttributes;
93 this.textValue = textValue;
111 this.stringValue = name;
121 StringBuilder result =
new StringBuilder(
"<entity");
123 if(this.stringValue != null && !this.stringValue.isEmpty()){
124 result.append(
" name=\"");
125 result.append(escapeHTML(this.stringValue));
129 if(this.uri != null && !this.uri.isEmpty()){
130 result.append(
" uri=\"");
131 result.append(escapeHTML(this.uri));
135 if(this.entityType != null && !this.entityType.isEmpty()){
136 result.append(
" type=\"");
137 result.append(this.entityType);
141 if(this.entityVisualURI != null && !this.entityVisualURI.isEmpty()){
142 result.append(
" visualRepresentation=\"");
143 if (this.entityVisualURI != null && !this.entityVisualURI.startsWith(
"http")) {
144 result.append(AppBean.getKBImagePrefix());
146 result.append(escapeHTML(this.entityVisualURI));
150 if(this.textValue != null && !this.textValue.isEmpty()){
151 result.append(
"><![CDATA[");
152 result.append(this.textValue);
153 result.append(
"]]></entity>");
158 return result.toString();
168 StringBuilder result =
new StringBuilder(
"<entity");
170 if (this.stringValue != null && !this.stringValue.isEmpty()) {
171 result.append(
" name=\"");
172 result.append(escapeHTML(this.stringValue));
176 if (this.uri != null && !this.uri.isEmpty()) {
177 result.append(
" uri=\"");
178 result.append(escapeHTML(this.uri));
182 if (this.entityType != null && !this.entityType.isEmpty()) {
183 result.append(
" type=\"");
184 result.append(this.entityType);
188 if (this.entityVisualURI != null && !this.entityVisualURI.isEmpty()) {
189 result.append(
" visualRepresentation=\"");
190 if (this.entityVisualURI != null && !this.entityVisualURI.startsWith(
"http")) {
191 result.append(AppBean.getKBImagePrefix());
193 result.append(escapeHTML(this.entityVisualURI));
197 if (this.textValue != null && !this.textValue.isEmpty()) {
198 result.append(
"><![CDATA[");
199 result.append(this.textValue);
200 result.append(
"]]></entity>");
205 return result.toString();
216 StringBuilder result =
new StringBuilder();
218 if(this.uri == null){
220 result.append(
"<trix:uri>");
221 result.append(
"http://knot.fit.vutbr.cz/annotations/knotOAExtension#anyEntity");
222 result.append(
"</trix:uri></trix:triple>");
223 return result.toString();
226 result.append(
"<trix:uri>");
227 result.append(escapeHTML(this.uri));
228 result.append(
"</trix:uri></trix:triple>");
231 result.append(
"<trix:triple><trix:uri>");
232 result.append(escapeHTML(this.uri));
233 result.append(
"</trix:uri><trix:uri>rdf:type</trix:uri><trix:name>");
234 result.append(entityType);
235 result.append(
"</trix:name></trix:triple>");
238 if(stringValue != null && !stringValue.isEmpty()){
239 result.append(
"<trix:triple><trix:uri>");
240 result.append(escapeHTML(this.uri));
241 result.append(
"</trix:uri><trix:name>name</trix:name><trix:typedLiteral datatype=\"http://www.w3.org/2001/XMLSchema#string\">");
242 result.append(escapeHTML(stringValue));
243 result.append(
"</trix:typedLiteral></trix:triple>");
247 if(textValue != null && !textValue.isEmpty()){
248 result.append(
"<trix:triple><trix:uri>");
249 result.append(escapeHTML(this.uri));
250 result.append(
"</trix:uri><trix:name>description</trix:name><trix:typedLiteral datatype=\"http://www.w3.org/2001/XMLSchema#string\">");
251 result.append(escapeHTML(textValue));
252 result.append(
"</trix:typedLiteral></trix:triple>");
256 if(entityVisualURI != null && !entityVisualURI.isEmpty()){
257 result.append(
"<trix:triple><trix:uri>");
258 result.append(escapeHTML(this.uri));
259 result.append(
"</trix:uri><trix:name>image</trix:name><trix:typedLiteral datatype=\"http://knot.fit.vutbr.cz/annotations/knotOAExtension#imageUri\">");
260 result.append(escapeHTML(entityVisualURI));
261 result.append(
"</trix:typedLiteral></trix:triple>");
264 if(entityAdditionalAttributes != null && !entityAdditionalAttributes.isEmpty()){
265 Collections.sort(entityAdditionalAttributes);
266 Iterator additionalAttrIt = entityAdditionalAttributes.iterator();
267 while(additionalAttrIt.hasNext()){
269 result.append(actualAttr.toXmlStringV2());
273 return result.toString();
282 StringBuilder result =
new StringBuilder(
"<entity");
283 boolean hasContent =
false;
285 result.append(
" name=\"");
286 if (this.stringValue != null && !this.stringValue.isEmpty()) {
287 result.append(escapeHTML(this.stringValue));
292 result.append(
" uri=\"");
293 if (this.uri != null && !this.uri.isEmpty()) {
294 result.append(escapeHTML(this.uri));
299 result.append(
" type=\"");
300 if (this.entityType != null && !this.entityType.isEmpty()) {
301 result.append(this.entityType);
306 result.append(
" image=\"");
307 if (this.entityVisualURI != null && !this.entityVisualURI.isEmpty()) {
308 if (!this.entityVisualURI.startsWith(
"http")) {
309 result.append(AppBean.getKBImagePrefix());
311 result.append(escapeHTML(this.entityVisualURI));
314 if (this.entityAdditionalAttributes != null && !this.entityAdditionalAttributes.isEmpty()) {
315 result.append(
"\">");
316 Collections.sort(entityAdditionalAttributes);
317 Iterator<EntityAdditionalAttribute> addtitionalAttrsIt = entityAdditionalAttributes.iterator();
318 while (addtitionalAttrsIt.hasNext()) {
320 if (a.
getName() != null && a.getName().equals(
"disambiguation")) {
321 a.setName(
"Disambiguation");
323 result.append(a.toXMLResponseStringV2());
330 if (this.textValue != null && !this.textValue.isEmpty()) {
332 result.append(
"\">");
334 result.append(
"<description><![CDATA[").append(this.textValue).append(
"]]></description>");
339 result.append(
"</entity>");
341 result.append(
"\"/>");
344 return result.toString();
354 public void setRawValues(Object values)
throws IllegalArgumentException {
355 @SuppressWarnings(
"unchecked") ArrayList<Object> valuesArray = (ArrayList<Object>)values;
356 @SuppressWarnings(
"unchecked") Map<String,String> parameters = (Map<String,String>)valuesArray.get(1);
357 String value = (String)valuesArray.get(2);
359 if(parameters.get(
"name") != null){
360 this.stringValue = parameters.get(
"name");
363 if(parameters.get(
"type") != null){
364 this.entityType = parameters.get(
"type");
367 if(parameters.get(
"uri") != null){
368 this.uri = parameters.get(
"uri");
371 if(parameters.get(
"visualRepresentation") != null){
372 this.entityVisualURI = parameters.get(
"visualRepresentation");
376 this.textValue = value;
388 StringBuilder sb =
new StringBuilder();
390 for (
int i = 0; i < n; i++) {
391 char c = s.charAt(i);
393 case '<': sb.append(
"<");
break;
394 case '>': sb.append(
">");
break;
395 case '&': sb.append(
"&");
break;
396 case '"': sb.append(
""");
break;
397 case '\'': sb.append(
"'");
break;
398 default: sb.append(c);
break;
401 return sb.toString();
421 return new Entity(this.entityType,this.stringValue,this.uri,this.entityVisualURI, this.textValue);
431 this.entityType = ((
Entity)value).getType();
432 this.stringValue = ((
Entity)value).getName();
433 this.uri = ((
Entity)value).getURI();
434 this.entityVisualURI = ((
Entity)value).getVisualRepresentation();
435 this.textValue = ((
Entity)value).getDescription();
445 ent.fromJSONString(value);
455 this.entityVisualURI = entityVisualURI;
464 this.entityType = entityType;
473 this.stringValue = stringValue;
485 return ((
Entity)getValue()).toJSONString();
517 public static final ArrayList<String> UNESACPED_CHARS =
new ArrayList<String>(Arrays.asList(
526 public static final ArrayList<String> ESCAPED_CHARS =
new ArrayList<String>(Arrays.asList(
549 public Entity(String type, String name, String URI, String visualRepresentation, String description) {
553 this.visualRepresentation = visualRepresentation;
554 this.description = description;
617 return visualRepresentation;
626 this.visualRepresentation = visualRepresentation;
644 this.description = description;
649 return "Entity{" +
"type=" + type
652 +
", visualRepresentation=" + visualRepresentation
653 +
", description=" + description +
'}';
663 String result = text;
664 for(
int i = 0; i < UNESACPED_CHARS.size(); i++){
665 result = result.replace(UNESACPED_CHARS.get(i), ESCAPED_CHARS.get(i));
678 String result = text;
679 for(
int i = 0; i < UNESACPED_CHARS.size(); i++){
680 result = result.replace(ESCAPED_CHARS.get(i),UNESACPED_CHARS.get(i));
692 StringBuilder result =
new StringBuilder();
693 if(this.name != null && !this.name.isEmpty()){
694 result.append(
"name = ");
695 result.append(escapeJSON(this.name));
699 if(this.type != null && !this.type.isEmpty()){
700 result.append(
"type = ");
701 result.append(escapeJSON(this.type));
705 if(this.URI != null && !this.URI.isEmpty()){
706 result.append(
"uri = ");
707 result.append(escapeJSON(this.URI));
711 if(this.visualRepresentation != null && !this.visualRepresentation.isEmpty()){
712 result.append(
"visualRepresentation = ");
713 result.append(escapeJSON(this.visualRepresentation));
717 if(this.description != null && !this.description.isEmpty()){
718 result.append(
"description = ");
719 result.append(escapeJSON(this.description));
723 if(result.length() > 2){
724 result.deleteCharAt(result.length()-1);
727 return result.toString();
736 if (text != null && !text.isEmpty()) {
737 String[] splited = text.split(
" ,");
738 for (
int i = 0; i < splited.length; i++) {
739 String[] pair = splited[i].split(
" = ");
740 if (pair.length == 2) {
741 if (pair[0].equals(
"name")) {
742 this.name = unescapeJSON(pair[1]);
745 if (pair[0].equals(
"type")) {
746 this.name = unescapeJSON(pair[1]);
749 if (pair[0].equals(
"uri")) {
750 this.URI = unescapeJSON(pair[1]);
753 if (pair[0].equals(
"visualRepresentation")) {
754 this.visualRepresentation = unescapeJSON(pair[1]);
757 if (pair[0].equals(
"description")) {
758 this.description = unescapeJSON(pair[1]);
String getVisualRepresentation()
void fromJSONString(String text)
void setDescription(String description)
Additional attribute of entity in annotation attribute.
void setType(String type)
Abstract class representing more complex attribute.
void setVisualRepresentation(String visualRepresentation)
String unescapeJSON(String text)
Singleton for storing global variables.
void setEntityVisualURI(String entityVisualURI)
Class representing vocabulary entity attribute.
void setValue(Object value)
void setFromJSONStringValue(String value)
void setEntityType(String entityType)
Entity(String type, String name, String URI, String visualRepresentation, String description)
String visualRepresentation
void setRawValues(Object values)
String toXMLResponseStringV2()
String getXmlAttributeName()
EntityAttribute(String name, String type, String URI, String visualRepresentation, String description)
void setEntityName(String name)
String getTypeOntologyUri()
void setStringValue(String stringValue)
void setDescription(String textValue)
Class holds values of dictionary entity.
List< EntityAdditionalAttribute > getEntityAdditionalAttributes()
void setName(String name)
void setEntityAdditionalAttributes(ArrayList< EntityAdditionalAttribute > EntityAdditionalAttributes)
String escapeHTML(String s)
String escapeJSON(String text)
static final String ENTITY_URI