Revision 8963
Added by ben leinfelder about 10 years ago
src/edu/ucsb/nceas/metacat/annotation/AnnotatorService.java | ||
---|---|---|
61 | 61 |
JSONArray rows = (JSONArray) jo.get("rows"); |
62 | 62 |
int count = rows.size(); |
63 | 63 |
Map<String, List<Object>> annotations = new HashMap<String, List<Object>>(); |
64 |
List<Object> values = null; |
|
65 |
|
|
66 |
// default the tags to a catch-all dynamic field as we develop |
|
67 |
String solrKey = "annotation_sm"; |
|
68 | 64 |
|
65 |
// use catch-all annotation field for the tags |
|
66 |
List<Object> tagValues = null; |
|
67 |
String tagKey = "annotation_sm"; |
|
68 |
|
|
69 |
// track the comments here |
|
70 |
List<Object> commentValues = null; |
|
71 |
String commentKey = "comment_sm"; |
|
72 |
|
|
69 | 73 |
for (int i = 0; i < count; i++){ |
70 | 74 |
JSONObject row = (JSONObject) rows.get(i); |
71 | 75 |
|
... | ... | |
76 | 80 |
continue; |
77 | 81 |
} |
78 | 82 |
|
83 |
// index the (semantic) tags |
|
79 | 84 |
// if the annotation told us the target index field, then use it |
80 | 85 |
Object field = row.get("field"); |
81 | 86 |
if (field != null) { |
82 |
solrKey = field.toString();
|
|
87 |
tagKey = field.toString();
|
|
83 | 88 |
} |
84 | 89 |
|
85 |
values = annotations.get(solrKey); |
|
86 |
if (values == null) { |
|
87 |
values = new ArrayList<Object>(); |
|
90 |
// make sure we have a place to store the values |
|
91 |
tagValues = annotations.get(tagKey); |
|
92 |
if (tagValues == null) { |
|
93 |
tagValues = new ArrayList<Object>(); |
|
88 | 94 |
} |
89 |
String key = "tags"; |
|
90 |
Object obj = row.get(key); |
|
95 |
Object obj = row.get("tags"); |
|
91 | 96 |
if (obj instanceof JSONArray) { |
92 |
JSONArray tags = (JSONArray) row.get(key);
|
|
93 |
values.addAll(tags);
|
|
97 |
JSONArray tags = (JSONArray) obj;
|
|
98 |
tagValues.addAll(tags);
|
|
94 | 99 |
} else { |
95 |
String value = row.get(key).toString();
|
|
96 |
values.add(value);
|
|
100 |
String value = obj.toString();
|
|
101 |
tagValues.add(value);
|
|
97 | 102 |
} |
98 |
annotations.put(solrKey, values); |
|
103 |
annotations.put(tagKey, tagValues); |
|
104 |
|
|
105 |
// index the comments |
|
106 |
commentValues = annotations.get(commentKey); |
|
107 |
if (commentValues == null) { |
|
108 |
commentValues = new ArrayList<Object>(); |
|
109 |
} |
|
110 |
Object commentObj = row.get("text"); |
|
111 |
if (commentObj != null) { |
|
112 |
String value = commentObj.toString(); |
|
113 |
commentValues.add(value); |
|
114 |
} |
|
115 |
annotations.put(commentKey, commentValues); |
|
99 | 116 |
|
100 | 117 |
} |
101 | 118 |
// just populate this one field for example |
Also available in: Unified diff
index both tags and text from annotateit.org