コード例 #1
0
 public void MorphologyTestFullHanReadings()
 {
     Init();
     List<string> h0 = new List<string>() { "Bei3-jing1-Da4-xue2" };
     List<string> h1 = null;
     List<string> h2 = new List<string>() { "zhu3-ren4" };
     MorphologyItem m0 = new MorphologyItem("北京大学", null, null, null, h0);
     MorphologyItem m1 = new MorphologyItem("生物系", null, null, null, h1);
     MorphologyItem m2 = new MorphologyItem("主任", null, null, null, h2);
     List<MorphologyItem> morphology = new List<MorphologyItem>() { m0, m1, m2 };
     string headersAsString = " { \"Content-Type\": \"application/json\", \"date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"server\": \"openresty\", \"strict-transport-security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"content-length\": \"72\", \"connection\": \"Close\" }";
     Dictionary<string, string> responseHeaders = new JavaScriptSerializer().Deserialize<Dictionary<string, string>>(headersAsString);
     Dictionary<string, object> content = new Dictionary<string, object>();
     content.Add("tokens", new List<string>(morphology.Select<MorphologyItem, string>((item) => item.Token))); ;
     content.Add("hanReadings", new List<List<string>>(morphology.Select<MorphologyItem, List<string>>((item) => item.HanReadings)));
     MorphologyResponse expected = new MorphologyResponse(morphology, responseHeaders, content, null);
     String mockedContent = expected.ContentAsJson;
     HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, mockedContent);
     _mockHttp.When(_testUrl + "morphology/han-readings").Respond(mockedMessage);
     MorphologyResponse response = _rosetteApi.Morphology("北京大学生物系主任.", feature: MorphologyFeature.hanReadings);
     Assert.AreEqual(expected, response);
 }
コード例 #2
0
 public void MorphologyTestFullLemmas()
 {
     Init();
     MorphologyItem m0 = new MorphologyItem("The", null, "the", null, null);
     MorphologyItem m1 = new MorphologyItem("quick", null, "quick", null, null);
     MorphologyItem m2 = new MorphologyItem("brown", null, "brown", null, null);
     MorphologyItem m3 = new MorphologyItem("fox", null, "fox", null, null);
     MorphologyItem m4 = new MorphologyItem("jumped", null, "jump", null, null);
     MorphologyItem m5 = new MorphologyItem(".", null, ".", null, null);
     List<MorphologyItem> morphology = new List<MorphologyItem>() { m0, m1, m2, m3, m4, m5 };
     string headersAsString = " { \"Content-Type\": \"application/json\", \"date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"server\": \"openresty\", \"strict-transport-security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"content-length\": \"72\", \"connection\": \"Close\" }";
     Dictionary<string, string> responseHeaders = new JavaScriptSerializer().Deserialize<Dictionary<string, string>>(headersAsString);
     Dictionary<string, object> content = new Dictionary<string, object>();
     content.Add("tokens", new List<string>(morphology.Select<MorphologyItem, string>((item) => item.Token)));;
     content.Add("lemmas", new List<string>(morphology.Select<MorphologyItem, string>((item) => item.Lemma)));
     MorphologyResponse expected = new MorphologyResponse(morphology, responseHeaders, content, null);
     String mockedContent = expected.ContentAsJson;
     HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, mockedContent);
     _mockHttp.When(_testUrl + "morphology/lemmas").Respond(mockedMessage);
     MorphologyResponse response = _rosetteApi.Morphology("The quick brown fox jumped.", feature: MorphologyFeature.lemmas);
     Assert.AreEqual(expected, response);
 }
コード例 #3
0
 public void MorphologyTestFullCompoundComponents()
 {
     Init();
     MorphologyItem m0 = new MorphologyItem("Er", null, null, new List<string>(), null);
     List<string> compoundComponents = new List<string>() { "Rechts", "Schutz", "Versicherungs", "Gesellschaft" };
     MorphologyItem m1 = new MorphologyItem("Rechtsschutzversicherungsgesellschaft", null, null, compoundComponents, null);
     List<MorphologyItem> morphology = new List<MorphologyItem>() { m0, m1 };
     string headersAsString = " { \"Content-Type\": \"application/json\", \"date\": \"Thu, 11 Aug 2016 15:47:32 GMT\", \"server\": \"openresty\", \"strict-transport-security\": \"max-age=63072000; includeSubdomains; preload\", \"x-rosetteapi-app-id\": \"1409611723442\", \"x-rosetteapi-concurrency\": \"50\", \"x-rosetteapi-request-id\": \"d4176692-4f14-42d7-8c26-4b2d8f7ff049\", \"content-length\": \"72\", \"connection\": \"Close\" }";
     Dictionary<string, string> responseHeaders = new JavaScriptSerializer().Deserialize<Dictionary<string, string>>(headersAsString);
     Dictionary<string, object> content = new Dictionary<string, object>();
     content.Add("tokens", new List<string>(morphology.Select<MorphologyItem, string>((item) => item.Token))); ;
     content.Add("compoundComponents", new List<List<string>>(morphology.Select<MorphologyItem, List<string>>((item) => item.CompoundComponents)));
     MorphologyResponse expected = new MorphologyResponse(morphology, responseHeaders, content, null);
     String mockedContent = expected.ContentAsJson;
     HttpResponseMessage mockedMessage = MakeMockedMessage(responseHeaders, HttpStatusCode.OK, mockedContent);
     _mockHttp.When(_testUrl + "morphology/compound-components").Respond(mockedMessage);
     MorphologyResponse response = _rosetteApi.Morphology("Er Rechtsschutzversicherungsgesellschaft.", feature: MorphologyFeature.compoundComponents);
     Assert.AreEqual(expected, response);
 }