Revision 52954
Added by Miriam Baglioni over 5 years ago
CommunityConfiguration.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.data.bulktag; |
2 | 2 |
|
3 | 3 |
import com.google.common.collect.Lists; |
4 |
import com.google.common.collect.Maps; |
|
4 | 5 |
import com.google.gson.Gson; |
5 | 6 |
import org.apache.commons.logging.Log; |
6 | 7 |
import org.apache.commons.logging.LogFactory; |
... | ... | |
27 | 28 |
private Map<String,Community> communities; |
28 | 29 |
|
29 | 30 |
//map subject -> communityid |
30 |
private transient final Map<String,List<Pair<String,SelectionCriteria>>> subjectMap = new HashMap<>();
|
|
31 |
private transient Map<String,List<Pair<String,SelectionCriteria>>> subjectMap = new HashMap<>(); |
|
31 | 32 |
//map datasourceid -> communityid |
32 |
private transient final Map<String,List<Pair<String,SelectionCriteria>>> datasourceMap = new HashMap<>();
|
|
33 |
private transient Map<String,List<Pair<String,SelectionCriteria>>> datasourceMap = new HashMap<>(); |
|
33 | 34 |
//map zenodocommunityid -> communityid |
34 |
private transient final Map<String,List<Pair<String,SelectionCriteria>>> zenodocommunityMap = new HashMap<>();
|
|
35 |
private transient Map<String,List<Pair<String,SelectionCriteria>>> zenodocommunityMap = new HashMap<>(); |
|
35 | 36 |
|
36 | 37 |
public CommunityConfiguration(final Map<String, Community> communities) { |
37 | 38 |
this.communities = communities; |
38 | 39 |
init(); |
39 | 40 |
} |
40 | 41 |
|
41 |
private void init() { |
|
42 |
for(Community c: getCommunityList()){ |
|
42 |
public void init() { |
|
43 |
|
|
44 |
if (subjectMap == null) { |
|
45 |
subjectMap = Maps.newHashMap(); |
|
46 |
} |
|
47 |
if (datasourceMap == null) { |
|
48 |
datasourceMap = Maps.newHashMap(); |
|
49 |
} |
|
50 |
if (zenodocommunityMap == null) { |
|
51 |
zenodocommunityMap = Maps.newHashMap(); |
|
52 |
} |
|
53 |
|
|
54 |
for(Community c : getCommunities().values()) { |
|
43 | 55 |
//get subjects |
44 | 56 |
final String id = c.getId(); |
45 | 57 |
for(String sbj : c.getSubjects()){ |
46 | 58 |
Pair<String,SelectionCriteria> p = new Pair<>(id,new SelectionCriteria(null)); |
47 |
add(sbj.toLowerCase(),p,subjectMap);
|
|
59 |
add(sbj.toLowerCase().trim() , p, subjectMap);
|
|
48 | 60 |
} |
49 | 61 |
//get datasources |
50 | 62 |
for(Datasource d: c.getDatasources()){ |
... | ... | |
80 | 92 |
} |
81 | 93 |
|
82 | 94 |
public List<String> getCommunityForSubjectValue(String value) { |
83 |
try { |
|
84 |
return subjectMap.get(value.toLowerCase()).stream().map(p -> p.getFst()).collect(Collectors.toList()); |
|
85 |
}catch(Exception e){ |
|
86 |
return new ArrayList<>(); |
|
87 |
} |
|
95 |
|
|
96 |
return getContextIds(subjectMap.get(value)); |
|
88 | 97 |
} |
89 | 98 |
|
90 | 99 |
public List<String> getCommunityForDatasourceValue(String value) { |
91 |
try { |
|
92 |
return datasourceMap.get(value.toLowerCase()).stream().map(p -> p.getFst()).collect(Collectors.toList()); |
|
93 |
}catch(Exception e){ |
|
94 |
return new ArrayList<>(); |
|
95 |
} |
|
100 |
|
|
101 |
return getContextIds(datasourceMap.get(value.toLowerCase())); |
|
96 | 102 |
} |
97 | 103 |
|
98 | 104 |
public List<String> getCommunityForZenodoCommunityValue(String value){ |
99 |
try { |
|
100 |
return zenodocommunityMap.get(value.toLowerCase()).stream().map(p -> p.getFst()).collect(Collectors.toList()); |
|
101 |
}catch(Exception e){ |
|
102 |
return new ArrayList<>(); |
|
103 | 105 |
|
106 |
return getContextIds(zenodocommunityMap.get(value.toLowerCase())); |
|
107 |
} |
|
108 |
|
|
109 |
private List<String> getContextIds(List<Pair<String, SelectionCriteria>> list) { |
|
110 |
if (list != null) { |
|
111 |
return list.stream().map(p -> p.getFst()).collect(Collectors.toList()); |
|
104 | 112 |
} |
113 |
return Lists.newArrayList(); |
|
105 | 114 |
} |
106 | 115 |
|
107 | 116 |
/* |
Also available in: Unified diff
fixed issues in the creation of the inverse map for bulk tagging