@Override public boolean addTo(String key, Collection<String> values) { boolean result = true; for (String value : values) { result &= this.addTo(key, value); } return result; }
/** * Load vocabulary data from a provided source url. * * @param sourceUrl the address from where to get the vocabulary source file * @return vocabulary data, if exists */ protected Map<String, TermData> load(final String sourceUrl) { SolrUpdateGenerator generator = new SolrUpdateGenerator(); Map<String, Double> fieldSelection = new HashMap<>(); return generator.transform(sourceUrl, fieldSelection); }
SolrUpdateGenerator generator = new SolrUpdateGenerator(); Map<String, Double> fieldSelection = new HashMap<String, Double>(); Map<String, TermData> data = generator.transform(realOntologyUrl, fieldSelection); if (data == null) { return 2; for (Map.Entry<String, Collection<String>> property : item.getValue().entrySet()) { String name = property.getKey(); for (String value : property.getValue()) {
if (line.trim().matches(ENTITY_SEPARATION_REGEX)) { if (this.counter > 0) { storeCrtTerm(); this.crtTerm.addTo("version", pieces[1]); this.crtTerm.addTo(TermData.ID_FIELD_NAME, "HEADER_INFO"); this.counter++; loadField(pieces[0], pieces[1]); storeCrtTerm(); if (isFieldSelected(TermData.TERM_CATEGORY_FIELD_NAME)) { propagateAncestors();
public Map<String, TermData> transform(String ontologyUrl, Map<String, Double> fieldSelection) { URL url; try { url = new URL(ontologyUrl); } catch (MalformedURLException ex) { return null; } return transform(url, fieldSelection); }
public void expandTermCategories(Map<String, TermData> data) { Set<String> result = new LinkedHashSet<>(); Queue<String> front = new LinkedList<>(); if (this.get(TERM_CATEGORY_FIELD_NAME) == null) { this.put(TERM_CATEGORY_FIELD_NAME, super.getEmptyCollection()); } result.add(this.id); front.addAll(this.get(TERM_CATEGORY_FIELD_NAME)); String nextTermId; while ((nextTermId = front.poll()) != null) { result.add(nextTermId); if (data.get(nextTermId).get(PARENT_FIELD_NAME) == null) { continue; } for (String parentTermId : data.get(nextTermId).get(PARENT_FIELD_NAME)) { parentTermId = parentTermId.replaceAll(PARENT_ID_REGEX, "$1"); if (!result.contains(parentTermId) && !front.contains(parentTermId)) { front.add(parentTermId); } } } this.put(TERM_CATEGORY_FIELD_NAME, result); } }
private void loadField(String name, String value) { if (!(isFieldSelected(name))) { return; } this.crtTerm.addTo(name, value.replaceFirst("^\"(.+)\"\\s*?(?:[A-Z]+|\\[).*", "$1") .replaceFirst("\\s+\\{.*$", "").replaceFirst("^(HP:\\d{7}) ! .*$", "$1").replace("\\\"", "\"")); }
for (Map.Entry<String, Collection<String>> property : item.getValue().entrySet()) { String name = property.getKey(); for (String value : property.getValue()) {
private void propagateAncestors() { for (String id : this.data.keySet()) { TermData term = this.data.get(id); term.expandTermCategories(this.data); } } }
if (line.trim().matches(ENTITY_SEPARATION_REGEX)) { if (this.counter > 0) { storeCrtTerm(); this.crtTerm.addTo("version", pieces[1]); this.crtTerm.addTo(TermData.ID_FIELD_NAME, "HEADER_INFO"); this.counter++; loadField(pieces[0], pieces[1]); storeCrtTerm(); if (isFieldSelected(TermData.TERM_CATEGORY_FIELD_NAME)) { propagateAncestors();
public Map<String, TermData> transform(String ontologyUrl, Map<String, Double> fieldSelection) { URL url; try { url = new URL(ontologyUrl); } catch (MalformedURLException ex) { return null; } return transform(url, fieldSelection); }
public void expandTermCategories(Map<String, TermData> data) { Set<String> result = new LinkedHashSet<>(); Queue<String> front = new LinkedList<>(); if (this.get(TERM_CATEGORY_FIELD_NAME) == null) { this.put(TERM_CATEGORY_FIELD_NAME, super.getEmptyCollection()); } result.add(this.id); front.addAll(this.get(TERM_CATEGORY_FIELD_NAME)); String nextTermId; while ((nextTermId = front.poll()) != null) { result.add(nextTermId); if (data.get(nextTermId).get(PARENT_FIELD_NAME) == null) { continue; } for (String parentTermId : data.get(nextTermId).get(PARENT_FIELD_NAME)) { parentTermId = parentTermId.replaceAll(PARENT_ID_REGEX, "$1"); if (!result.contains(parentTermId) && !front.contains(parentTermId)) { front.add(parentTermId); } } } this.put(TERM_CATEGORY_FIELD_NAME, result); } }
private void loadField(String name, String value) { if (!(isFieldSelected(name))) { return; } this.crtTerm.addTo(name, value.replaceFirst("^\"(.+)\"\\s*?(?:[A-Z]+|\\[).*", "$1") .replaceFirst("\\s+\\{.*$", "").replaceFirst("^(HP:\\d{7}) ! .*$", "$1").replace("\\\"", "\"")); }
@Override public boolean addTo(String key, Collection<String> values) { boolean result = true; for (String value : values) { result &= this.addTo(key, value); } return result; }
private void propagateAncestors() { for (String id : this.data.keySet()) { TermData term = this.data.get(id); term.expandTermCategories(this.data); } } }