14 package cz.vutbr.fit.knot.annotations.entity;
18 import java.io.Serializable;
19 import javax.persistence.Basic;
20 import javax.persistence.Column;
21 import javax.persistence.Entity;
22 import javax.persistence.GeneratedValue;
23 import javax.persistence.GenerationType;
24 import javax.persistence.Id;
25 import javax.persistence.JoinColumn;
26 import javax.persistence.Lob;
27 import javax.persistence.ManyToOne;
28 import javax.persistence.NamedQueries;
29 import javax.persistence.NamedQuery;
30 import javax.persistence.Table;
31 import javax.xml.xpath.XPathExpressionException;
41 @Table(name =
"fragment")
43 @NamedQuery(name =
"Fragment.findAll", query =
"SELECT f FROM Fragment f"),
44 @NamedQuery(name =
"Fragment.findById", query =
"SELECT f FROM Fragment f WHERE f.id = :id"),
45 @NamedQuery(name =
"Fragment.findByAnnotation", query =
"SELECT f FROM Fragment f WHERE f.annotation = :annotation"),
46 @NamedQuery(name =
"Fragment.findByOffset", query =
"SELECT f FROM Fragment f WHERE f.offset = :offset"),
47 @NamedQuery(name =
"Fragment.findByLength", query =
"SELECT f FROM Fragment f WHERE f.length = :length")})
48 public class Fragment implements Serializable, Comparable<Object> {
50 private static final long serialVersionUID = 1L;
55 @GeneratedValue(strategy = GenerationType.IDENTITY)
56 @Basic(optional =
false)
62 @Basic(optional = false)
63 @Column(name = "annotation", nullable = false, insertable = false, updatable = false)
64 private
int annotation;
69 @Column(name = "frPath")
74 @Column(name = "frOffset")
75 private Integer offset;
79 @Column(name = "frLength")
80 private Integer length;
84 @Basic(optional = false)
86 @Column(name = "annotatedText")
87 private String annotatedText;
91 @Basic(optional = false)
92 @Column(name = "isGood")
93 private
boolean isGood;
97 @ManyToOne(optional = false)
98 @JoinColumn(name = "annotation", referencedColumnName = "
id")
126 public Fragment(String path, Integer offset, Integer length, String annotatedText,
Annotation refAnnotation) {
128 this.offset = offset;
129 this.length = length;
130 this.annotatedText = annotatedText;
131 this.refAnnotation = refAnnotation;
145 public Fragment(String path, Integer offset, Integer length, String annotatedText,
Annotation refAnnotation, Boolean isGood) {
147 this.offset = offset;
148 this.length = length;
149 this.annotatedText = annotatedText;
150 this.refAnnotation = refAnnotation;
151 this.isGood = isGood;
161 public Fragment(String path, Integer offset, Integer length) {
163 this.offset = offset;
164 this.length = length;
201 this.annotation = annotation;
237 this.offset = offset;
255 this.length = length;
264 return annotatedText;
273 this.annotatedText = annotatedText;
282 return refAnnotation;
291 this.refAnnotation = refAnnotation;
310 this.isGood = isGood;
316 hash += (
id != null ? id.hashCode() : 0);
317 hash += (offset != null ? offset.hashCode() : 0);
318 hash += (length != null ? length.hashCode() : 0);
319 hash += (annotatedText != null ? annotatedText.hashCode() : 0);
333 if (!(
object instanceof
Fragment)) {
336 Fragment other = (Fragment)
object;
338 if (this.path != other.
path && (
this.path == null || !
this.path.equals(other.
path))) {
341 if (this.offset != other.
offset && (
this.offset == null || !
this.offset.equals(other.
offset))) {
344 if (this.length != other.
length && (
this.length == null || !
this.length.equals(other.
length))) {
347 if ((this.annotatedText == null) ? (other.annotatedText != null) : !this.annotatedText.equals(other.
annotatedText)) {
366 if (getClass() != obj.getClass()) {
370 if ((this.path == null) ? (other.path != null) : !this.path.equals(other.
path)) {
371 if ((this.path == null) ? (other.path != null) : !this.path.equals(other.
path.concat(
"/text()"))) {
375 if (this.offset != other.
offset && (
this.offset == null || !
this.offset.equals(other.
offset))) {
378 if (this.length != other.
length && (
this.length == null || !
this.length.equals(other.
length))) {
381 if ((this.annotatedText == null) ? (other.annotatedText != null) : !this.annotatedText.equals(other.
annotatedText)) {
403 if (this.offset != uf.
getOffset() && (this.offset == null || !this.offset.equals(uf.getOffset()))) {
406 if (this.length != uf.
getLength() && (this.length == null || !this.length.equals(uf.getLength()))) {
409 if ((this.annotatedText == null) ? (uf.getText() != null) : !this.annotatedText.equals(uf.getText())) {
432 this.path = uf.getXPathString();
434 this.path = uf.getXPathString() +
"/text()";
436 this.offset = uf.getOffset();
437 this.length = uf.getLength();
438 this.annotatedText = uf.getText();
443 return "cz.vutbr.fit.knot.annotations.entity.Fragment[id=" +
id +
"]";
454 invalid =
" valid=\"false\"";
456 return "<a:fragment" + invalid +
">"
457 +
"<a:path>" + path +
"</a:path>"
458 +
"<a:offset>" + offset +
"</a:offset>"
459 +
"<a:length>" + length +
"</a:length>"
460 +
"<a:annotatedText>" + Util.toHTMLString(annotatedText) +
"</a:annotatedText>"
470 String annotUri = this.getRefAnnotation().getSource();
471 String fragXpointer = this.getXpointerV2();
473 return "<oa:SpecificResource rdf:about=\"" + annotUri +
"#" + fragXpointer +
"\">"
475 +
"<oa:FragmentSelector rdf:about=\"" + annotUri +
"#" + fragXpointer +
"#selector\">"
476 +
"<dcterms:conformsTo rdf:resource=\"http://tools.ietf.org/rfc/rfc3023\" />"
477 +
"<rdf:value>" + fragXpointer +
"</rdf:value></oa:FragmentSelector></oa:hasSelector>"
478 +
"<oa:hasSource><dctypes:Text rdf:about=\"" + annotUri +
"\"><dc:format>text/xml</dc:format>"
479 +
"</dctypes:Text></oa:hasSource></oa:SpecificResource>";
488 return "xpointer(string-range(" + path +
",\"" + annotatedText +
"\", " + offset +
", " + length +
"))";
497 String xpointer =
"xpointer(string-range(" + path +
",'" + annotatedText +
"', " + offset +
", " + length +
"))";
498 return Util.toHTMLString(xpointer);
510 if (!(
object instanceof
Fragment)) {
511 throw new UnsupportedOperationException(
"Not supported yet.");
513 Fragment other = (Fragment)
object;
514 int compareResult = offset.compareTo(other.getOffset());
515 if (compareResult == 0) {
516 compareResult = length.compareTo(other.getLength());
519 return compareResult;
Fragment(String path, Integer offset, Integer length)
UpdatableFragment toUpdatableFragment()
int compareTo(Object object)
boolean fragmentEqualsWUF(UpdatableFragment uf)
String getAnnotatedText()
Fragment(String path, Integer offset, Integer length, String annotatedText, Annotation refAnnotation, Boolean isGood)
Annotation getRefAnnotation()
Fragment(String path, Integer offset, Integer length, String annotatedText, Annotation refAnnotation)
boolean contentEquals(Object obj)
void setAnnotation(int annotation)
void setAnnotatedText(String annotatedText)
Class for XML document fragment.
void setPath(String path)
void setLength(Integer length)
boolean equals(Object object)
void setOffset(Integer offset)
void setRefAnnotation(Annotation refAnnotation)
Utility class (manipulates RFC 3339 dates)
Class representing annotated fragment.
Class representing annotation.
void updateWithUpdatableFragment(UpdatableFragment uf)
void setIsGood(boolean isGood)