source: SRUAggregator/trunk/src/main/java/eu/clarin/sru/fcs/aggregator/scan/Corpus.java @ 5897

Last change on this file since 5897 was 5897, checked in by emanuel.dima@uni-tuebingen.de, 9 years ago

fixed language codes translations (now using ISO693-3) + misc

File size: 3.8 KB
Line 
1package eu.clarin.sru.fcs.aggregator.scan;
2
3import com.fasterxml.jackson.annotation.JsonIgnore;
4import eu.clarin.sru.fcs.aggregator.lang.LanguagesISO693_3;
5import java.util.ArrayList;
6import java.util.Collections;
7import java.util.HashSet;
8import java.util.List;
9import java.util.Set;
10import java.util.regex.Pattern;
11
12/**
13 * Represents information about corpus resource, such as corpus handle (id),
14 * institution, title, description, language(s), etc. Does not store the
15 * information about corpus sub-corpora.
16 *
17 * @author Yana Panchenko
18 */
19public class Corpus {
20
21        public static final String ROOT_HANDLE = "root";
22        public static final Pattern HANDLE_WITH_SPECIAL_CHARS = Pattern.compile(".*[<>=/()\\s].*");
23
24        private Institution institution;
25        private String endpointUrl;
26        private String handle;
27        private Integer numberOfRecords;
28        private String displayName;
29        private Set<String> languages = new HashSet<String>();
30        private String landingPage;
31        private String title;
32        private String description;
33        public List<Corpus> subCorpora = Collections.synchronizedList(new ArrayList<Corpus>());
34
35        public Corpus() {
36        }
37
38        public Corpus(Institution institution, String endpointUrl) {
39                this.institution = institution;
40                this.endpointUrl = endpointUrl;
41        }
42
43        @JsonIgnore
44        public String getId() {
45                return endpointUrl + "#" + handle;
46        }
47
48        public void addCorpus(Corpus c) {
49                subCorpora.add(c);
50        }
51
52        public List<Corpus> getSubCorpora() {
53                return Collections.unmodifiableList(subCorpora);
54        }
55
56        public void setSubCorpora(List<Corpus> subCorpora) {
57                this.subCorpora = subCorpora;
58        }
59
60
61        public String getHandle() {
62                return handle;
63        }
64
65        public void setHandle(String value) {
66                this.handle = value;
67        }
68
69        public Integer getNumberOfRecords() {
70                return numberOfRecords;
71        }
72
73        public void setNumberOfRecords(Integer numberOfRecords) {
74                this.numberOfRecords = numberOfRecords;
75        }
76
77        public String getDisplayName() {
78                return displayName;
79        }
80
81        public void setDisplayName(String displayName) {
82                this.displayName = displayName;
83        }
84
85        public String getEndpointUrl() {
86                return endpointUrl;
87        }
88
89        public void setEndpointUrl(String endpointUrl) {
90                this.endpointUrl = endpointUrl;
91        }
92
93        public Institution getInstitution() {
94                return institution;
95        }
96
97        public void setInstitution(Institution institution) {
98                this.institution = institution;
99        }
100
101        public Set<String> getLanguages() {
102                return languages;
103        }
104
105        public void setLanguages(Set<String> languages) {
106                this.languages = languages;
107        }
108
109        public void addLanguage(String language) {
110                if (LanguagesISO693_3.getInstance().getCodes().contains(language)) {
111                        this.languages.add(language);
112                } else {
113                        String code = LanguagesISO693_3.getInstance().codeForName(language);
114                        if (code != null) {
115                                this.languages.add(code);
116                        } else {
117                                this.languages.add(language);
118                        }
119                }
120        }
121
122        public String getLandingPage() {
123                return landingPage;
124        }
125
126        public void setLandingPage(String landingPage) {
127                this.landingPage = landingPage;
128        }
129
130        public String getDescription() {
131                return description;
132        }
133
134        public void setDescription(String description) {
135                this.description = description;
136        }
137
138        @Override
139        public int hashCode() {
140                int hash = 3;
141                hash = 29 * hash + (this.endpointUrl != null ? this.endpointUrl.hashCode() : 0);
142                hash = 29 * hash + (this.handle != null ? this.handle.hashCode() : 0);
143                return hash;
144        }
145
146        @Override
147        public boolean equals(Object obj) {
148                if (obj == null) {
149                        return false;
150                }
151                if (getClass() != obj.getClass()) {
152                        return false;
153                }
154                final Corpus other = (Corpus) obj;
155                if ((this.endpointUrl == null) ? (other.endpointUrl != null) : !this.endpointUrl.equals(other.endpointUrl)) {
156                        return false;
157                }
158                if ((this.handle == null) ? (other.handle != null) : !this.handle.equals(other.handle)) {
159                        return false;
160                }
161                return true;
162        }
163
164        @Override
165        public String toString() {
166                return "Corpus{" + "endpointUrl=" + endpointUrl + ", handle=" + handle + '}';
167        }
168
169}
Note: See TracBrowser for help on using the repository browser.