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

Last change on this file since 5957 was 5957, checked in by emanuel.dima@uni-tuebingen.de, 9 years ago
  1. alpha15: added support for new spec explains/search; misc UI corrections
File size: 3.8 KB
Line 
1package eu.clarin.sru.fcs.aggregator.scan;
2
3import eu.clarin.sru.fcs.aggregator.lang.LanguagesISO693_3;
4import java.util.ArrayList;
5import java.util.Collections;
6import java.util.HashSet;
7import java.util.List;
8import java.util.Set;
9import java.util.regex.Pattern;
10import org.slf4j.LoggerFactory;
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        private static final org.slf4j.Logger log = LoggerFactory.getLogger(Corpus.class);
22
23        public static final String ROOT_HANDLE = "root";
24        public static final Pattern HANDLE_WITH_SPECIAL_CHARS = Pattern.compile(".*[<>=/()\\s].*");
25
26        private Institution institution;
27        private Endpoint endpoint;
28        private String handle;
29        private Integer numberOfRecords;
30        private Set<String> languages = new HashSet<String>();
31        private String landingPage;
32        private String title;
33        private String description;
34        public List<Corpus> subCorpora = Collections.synchronizedList(new ArrayList<Corpus>());
35
36        public Corpus() {
37        }
38
39        public Corpus(Institution institution, Endpoint endpoint) {
40                this.institution = institution;
41                this.endpoint = endpoint;
42        }
43
44        public String getId() {
45                return endpoint.getUrl() + "#" + handle;
46        }
47
48        public void setId(String id) { // dumb setter for JsonDeserialization
49        }
50
51        public void addCorpus(Corpus c) {
52                subCorpora.add(c);
53        }
54
55        public List<Corpus> getSubCorpora() {
56                return Collections.unmodifiableList(subCorpora);
57        }
58
59        public void setSubCorpora(List<Corpus> subCorpora) {
60                this.subCorpora = subCorpora;
61        }
62
63        public String getHandle() {
64                return handle;
65        }
66
67        public void setHandle(String value) {
68                this.handle = value;
69        }
70
71        public Integer getNumberOfRecords() {
72                return numberOfRecords;
73        }
74
75        public void setNumberOfRecords(Integer numberOfRecords) {
76                this.numberOfRecords = numberOfRecords;
77        }
78
79        public Endpoint getEndpoint() {
80                return endpoint;
81        }
82
83        public void setEndpoint(Endpoint endpoint) {
84                this.endpoint = endpoint;
85        }
86
87        public Institution getInstitution() {
88                return institution;
89        }
90
91        public void setInstitution(Institution institution) {
92                this.institution = institution;
93        }
94
95        public Set<String> getLanguages() {
96                return languages;
97        }
98
99        public void setLanguages(Set<String> languages) {
100                this.languages = languages;
101        }
102
103        public void addLanguage(String language) {
104                if (LanguagesISO693_3.getInstance().getCodes().contains(language)) {
105                        this.languages.add(language);
106                } else {
107                        String code = LanguagesISO693_3.getInstance().codeForName(language);
108                        this.languages.add(code == null ? language : code);
109                }
110        }
111
112        public String getLandingPage() {
113                return landingPage;
114        }
115
116        public void setLandingPage(String landingPage) {
117                this.landingPage = landingPage;
118        }
119
120        public String getTitle() {
121                return title;
122        }
123
124        void setTitle(String title) {
125                this.title = title;
126        }
127
128        public String getDescription() {
129                return description;
130        }
131
132        public void setDescription(String description) {
133                this.description = description;
134        }
135
136        @Override
137        public int hashCode() {
138                int hash = 3;
139                hash = 29 * hash + (this.endpoint != null ? this.endpoint.hashCode() : 0);
140                hash = 29 * hash + (this.handle != null ? this.handle.hashCode() : 0);
141                return hash;
142        }
143
144        @Override
145        public boolean equals(Object obj) {
146                if (obj == null) {
147                        return false;
148                }
149                if (getClass() != obj.getClass()) {
150                        return false;
151                }
152                final Corpus other = (Corpus) obj;
153                if ((this.endpoint == null) ? (other.endpoint != null) : !this.endpoint.equals(other.endpoint)) {
154                        return false;
155                }
156                if ((this.handle == null) ? (other.handle != null) : !this.handle.equals(other.handle)) {
157                        return false;
158                }
159                return true;
160        }
161
162        @Override
163        public String toString() {
164                return "Corpus{" + "endpoint=" + endpoint + ", handle=" + handle + '}';
165        }
166
167}
Note: See TracBrowser for help on using the repository browser.