def process_tags(self, result): tags = [] tagsDict = {} # Build a dictionary of the tags for doc in result: # Get Anotar data from Solr data doc = JsonSimple(doc.get("jsonString")) # Get actual tag text tag = doc.getString(None, ["content", "literal"]) # Find out if they have locators locs = doc.getJsonSimpleList(["annotates", "locators"]).size() if locs == 0: # Basic tags, just aggregate counts if tag in tagsDict: # We've seen it before, just increment the counter existing = tagsDict[tag] count = existing.getInteger(0, ["tagCount"]) existing.getJsonObject().put("tagCount", str(count + 1)) else: # First time, store this object doc.getJsonObject().put("tagCount", str(1)) tagsDict[tag] = doc else: # Tags with a locator, special case for images etc. tags.append(doc.toString()) # Push all the 'basic' counts into the list to return for tag in tagsDict: tags.append(tagsDict[tag].toString()) return "[" + ",".join(tags) + "]"
def __activate__(self, context): self.vc = context responseType = "text/html; charset=UTF-8" responseMsg = "" func = self.vc("formData").get("func") if func == "placeName": try: placeName = self.vc("formData").get("q") url = "http://ws.geonames.org/searchJSON?fuzzy=0.7&q=" + placeName client = BasicHttpClient(url) get = GetMethod(url) statusInt = client.executeMethod(get) r = str(statusInt) json = JsonSimple(get.getResponseBodyAsString().strip()) for geoName in json.getJsonSimpleList("geonames"): responseMsg += "%s, %s|%s \n" % (geoName.getString(None, "name"), geoName.getString(None, "countryName"), geoName.getString(None, "geonameId")) except Exception, e: print "exception: ", str(e) r = str(e), None responseType = "text/plain; charset=UTF-8"