예제 #1
0
        private static WordModel ParseJsonSynonyms(WordModel model, string jsonString)
        {
            var parsed = JObject.Parse(jsonString);
            JToken token;
            if (parsed.TryGetValue("noun", out token))
            {
                var synonyms = token["syn"];
                if (synonyms != null)
                {
                    model.NounSynonyms = synonyms.AsEnumerable().Select(s => new WordModel(s.ToString())).ToList();
                }
            }
            if (parsed.TryGetValue("verb", out token))
            {
                var synonyms = token["syn"];
                if (synonyms != null)
                {
                    model.VerbSynonyms = synonyms.AsEnumerable().Select(s => new WordModel(s.ToString())).ToList();
                }
            }
            if (parsed.TryGetValue("adjective", out token))
            {
                var synonyms = token["syn"];
                if (synonyms != null)
                {
                    model.AdjectiveSynonyms = synonyms.AsEnumerable().Select(s => new WordModel(s.ToString())).ToList();
                }
            }
            if (parsed.TryGetValue("adverb", out token))
            {
                var synonyms = token["syn"];
                if (synonyms != null)
                {
                    model.AdverbSynonyms = synonyms.AsEnumerable().Select(s => new WordModel(s.ToString())).ToList();
                }
            }
            model.SynonymsQueried = true;

            return model;
        }
예제 #2
0
 public static void GetSynonyms(ref WordModel model)
 {
     var jsonString = JsonQuery(String.Format("http://words.bighugelabs.com/api/2/{0}/{1}/json", APIkey, model.Word));
     ParseJsonSynonyms(model, jsonString);
 }