<commit_before>/**
 * Stub code for reading data from Cloudant in a whisk action
 */

//import KituraNet
import Dispatch
import Foundation

func main(args:[String:Any]) -> [String:Any] {

    let result:[String:Any] = [String:Any]()
    
    //process alchemy
    print("inside alchemy analysis")

    // return, which should be a dictionary
    return result
}<commit_msg>Implemented Alchmey image tagging OpenWhisk action<commit_after>/**
 * Stub code for reading data from Cloudant in a whisk action
 */

import KituraNet
import Dispatch
import Foundation

func main(args:[String:Any]) -> [String:Any] {
       
    let alchemyKey: String? = args["alchemyKey"] as? String
    let imageURL: String? = args["imageURL"] as? String
    
    let url: String = "https://gateway-a.watsonplatform.net/calls/url/URLGetRankedImageKeywords?url=\(imageURL!)&outputMode=json&apikey=\(alchemyKey!)"
    
    
    // Force KituraNet call to run synchronously on a global queue
    var str = "No response"
    dispatch_sync(dispatch_get_global_queue(0, 0)) {

            Http.get(url) { response in

                do {
                   str = try response!.readString()!
                } catch {
                    print("Error \(error)")
                }

            }
    }

    // Assume string is JSON
    print("Got string \(str)")
    var result:[String:Any]?

    // Convert to NSData
    let data = str.bridge().dataUsingEncoding(NSUTF8StringEncoding)!
    do {
        result = try NSJSONSerialization.jsonObject(with: data, options: []) as? [String: Any]
    } catch {
        print("Error \(error)")
    }

    // return, which should be a dictionary
    print("Result is \(result!)")
    return result!
}
{'fraction_non_alphanumeric': 0.11805961426066627, 'fraction_numerical': 0.0017533606078316774, 'mean_word_length': 2.566666666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4997193', 'n_tokens_mistral': 524, 'n_tokens_neox': 494, 'n_words': 143}