RosetteFile Class

RosetteFile: Custom Datatype containing information about files for upload, and methods to read the files

示例#1
0
文件: CAPI.cs 项目: cp2boston/csharp
 /// <summary>Tokens
 /// <para>
 /// (POST)Tokens Endpoint: Divides the input into tokens.
 /// </para>
 /// </summary>
 /// <param name="file">RosetteFile: RosetteFile Object containing the file (and possibly options) to upload</param>
 /// <returns>Dictionary&lt;string, object&gt;: Dictionary containing the results of the request. 
 /// The response contains a list of tokens.
 /// </returns>
 public Dictionary<string, object> Tokens(RosetteFile file)
 {
     _uri = "tokens/";
     return Process(file);
 }
示例#2
0
文件: CAPI.cs 项目: cp2boston/csharp
        /// <summary>Process
        /// <para>
        /// Process: Internal function to convert a RosetteFile into a dictionary to use for getResponse
        /// </para>
        /// </summary>
        /// <param name="file">RosetteFile: File being uploaded to use as a request to the Rosette server.</param>
        /// <returns>Dictionary&lt;string, object&gt;: Dictionary containing the results of the response from the server from the getResponse call.</returns>
        private Dictionary<string, Object> Process(RosetteFile file)
        {
            Dictionary<string, string> dict = new Dictionary<string, string>(){
                { "content", file.getFileDataString()},
                { "contentType", file.getDataType()},
                { "unit", "doc"},
            };

            if(file.getOptions() != null){
                Dictionary<string, string> opts = new JavaScriptSerializer().Deserialize<Dictionary<string, string>>(file.getOptions());
                dict = (Dictionary<string, string>)dict.Concat(opts.Where(x=> !dict.Keys.Contains(x.Key)));
            }


            return getResponse(SetupClient(), new JavaScriptSerializer().Serialize(dict));
        }
示例#3
0
文件: CAPI.cs 项目: cp2boston/csharp
 /// <summary>Relationships
 /// <para>
 /// (POST)Relationships Endpoint: Returns each relationship extracted from the input.
 /// </para>
 /// </summary>
 /// <param name="file">RosetteFile: RosetteFile Object containing the file (and possibly options) to upload</param>
 /// <returns>
 /// The response is a list of extracted relationships. A relationship contains
 /// 
 /// predicate - usually the main verb, property or action that is expressed by the text
 /// arg1 - usually the subject, agent or main actor of the relationship
 /// arg2 [optional] - complements the predicate and is usually the object, theme or patient of the relationship
 /// arg3 [optional] - usually an additional object in ditransitive verbs
 /// adjuncts [optional] - contain all optional parts of a relationship which are not temporal or locative expressions
 /// locatives [optional] - usually express the locations the action expressed by the relationship took place
 /// temporals [optional] - usually express the time in which the action expressed by the relationship took place
 /// confidence = a measure of quality of relationship extraction, between 0 - 1
 /// </returns>
 public Dictionary<string, object> Relationships(RosetteFile file)
 {
     _uri = "relationships/";
     return Process(file);
 }
示例#4
0
文件: CAPI.cs 项目: cp2boston/csharp
 /// <summary>Sentiment
 /// <para>
 /// (POST)Sentiment Endpoint: Analyzes the positive and negative sentiment expressed by the input.
 /// </para>
 /// </summary>
 /// <param name="file">RosetteFile: RosetteFile Object containing the file (and possibly options) to upload</param>
 /// <returns>Dictionary&lt;string, object&gt;: Dictionary containing the results of the request. 
 /// The response contains sentiment analysis results.
 /// </returns>
 public Dictionary<string, object> Sentiment(RosetteFile file)
 {
     _uri = "sentiment/";
     return Process(file);
 }
示例#5
0
文件: CAPI.cs 项目: cp2boston/csharp
 /// <summary>Language
 /// <para>
 /// (POST)Language Endpoint: Returns list of candidate languages in order of descending confidence.
 /// </para>
 /// </summary>
 /// <param name="file">RosetteFile: RosetteFile Object containing the file (and possibly options) to upload</param>
 /// <returns>Dictionary&lt;string, object&gt;: Dictionary containing the results of the request. 
 /// The response is an ordered list of detected languages, including language and detection confidence, sorted by descending confidence.
 /// </returns>
 public Dictionary<string, object> Language(RosetteFile file)
 {
     _uri = "language/";
     return Process(file);
 }
示例#6
0
文件: CAPI.cs 项目: cp2boston/csharp
 /// <summary>Morphology
 /// <para>
 /// (POST)Morphology Endpoint: Returns morphological analysis of input.
 /// </para>
 /// </summary>
 /// <param name="file">RosetteFile: RosetteFile Object containing the file (and possibly options) to upload</param>
 /// <param name="feature">(string, optional): Description of what morphology feature to request from the Rosette server</param>
 /// <returns>Dictionary&lt;string, object&gt;: Dictionary containing the results of the request. 
 /// The response may include lemmas, part of speech tags, compound word components, and Han readings. 
 /// Support for specific return types depends on language.
 /// </returns>
 public Dictionary<string, object> Morphology(RosetteFile file, string feature = "complete")
 {
     _uri = Morphofeatures.Contains(feature) ? "morphology/" + feature : "morphology/complete";
     return Process(file);
 }
示例#7
0
文件: CAPI.cs 项目: cp2boston/csharp
 /// <summary>Categories
 /// <para>
 /// (POST)Categories Endpoint: Returns an ordered list of categories identified in the input. The categories are Tier 1 contextual categories defined in the QAG Taxonomy.
 /// </para>
 /// </summary>
 /// <param name="file">RosetteFile: RosetteFile Object containing the file (and possibly options) to upload</param>
 /// <returns>Dictionary&lt;string, object&gt;: Dictionary containing the results of the request.
 /// The response is the contextual categories identified in the input.
 /// </returns>
 public Dictionary<string, object> Categories(RosetteFile file)
 {
     _uri = "categories/";
     return Process(file);
 }
示例#8
0
文件: CAPI.cs 项目: cp2boston/csharp
 /// <summary>Entity
 /// <para>
 /// (POST)Entity Endpoint: Returns each entity extracted from the input.
 /// </para>
 /// </summary>
 /// <param name="file">RosetteFile: RosetteFile Object containing the file (and possibly options) to upload</param>
 /// <returns>Dictionary&lt;string, object&gt;: Dictionary containing the results of the request. 
 /// The response is a list of extracted entities. 
 /// Each entity includes chain ID (all instances of the same entity share a chain id), mention (entity text in the input), 
 /// normalized text (the most complete form of this entity that appears in the input), count (how many times this entity appears in the input), 
 /// and the confidence associated with the extraction.
 /// </returns>
 public Dictionary<string, object> Entity(RosetteFile file)
 {
     _uri = "entities/";
     return Process(file);
 }
        public void Relationships_File_Test()
        {
            _mockHttp.When(_testUrl + "relationships")
                .Respond("application/json", "{'response': 'OK'}");

            RosetteFile f = new RosetteFile(_tmpFile);
            var response = _rosetteApi.Relationships(f);
            # pragma warning disable 618
            Assert.AreEqual(response.Content["response"], "OK");
            # pragma warning restore 618
        }
示例#10
0
        public void EntitiesLinked_File_Test()
        {
            _mockHttp.When(_testUrl + "entities/linked")
                .Respond("application/json", "{'response': 'OK'}");

            RosetteFile f = new RosetteFile(_tmpFile);
            var response = _rosetteApi.Entity(f, true);
            # pragma warning disable 618
            Assert.AreEqual(response.Content["response"], "OK");
            # pragma warning restore 618
        }
示例#11
0
        //[Test]
        public void doTest()
        {
            string tmpFile = Path.GetTempFileName();
            StreamWriter sw = File.AppendText(tmpFile);
            sw.WriteLine(@"<html><head><title>New Ghostbusters Film</title></head><body><p>Original Ghostbuster Dan Aykroyd, who also co-wrote the 1984 Ghostbusters film, couldn’t be more pleased with the new all-female Ghostbusters cast, telling The Hollywood Reporter, “The Aykroyd family is delighted by this inheritance of the Ghostbusters torch by these most magnificent women in comedy.”</p></body></html>");
            sw.Flush();
            sw.Close();

            RosetteFile rf = new RosetteFile(tmpFile, "text/plain", @"{""language"":""eng""}");

            CAPI rosetteApi = new CAPI("boguskey", "http://seuss.basistech.net:8181/rest/v1", 1);
            RosetteResponse result = rosetteApi.Sentiment(rf);
            System.Diagnostics.Debug.WriteLine(result.ContentAsJson);

            if (File.Exists(tmpFile)) {
                File.Delete(tmpFile);
            }
        }
示例#12
0
        public void RosetteFileClassTest()
        {
            string tmpFile = Path.GetTempFileName();
            StreamWriter sw = File.AppendText(tmpFile);
            sw.WriteLine("Rosette API Unit Test");
            sw.Flush();
            sw.Close();

            RosetteFile f = new RosetteFile(tmpFile, "application/octet-stream", null);
            Assert.IsNotNull(f.Filename, "Filename is null");
            Assert.AreEqual(tmpFile, f.Filename, "Filename does not match");
            Assert.AreEqual("application/octet-stream", f.ContentType, "ContentType does not match");
            Assert.IsNull(f.Options, "Options does not match");

            byte[] b = f.getFileData();
            Assert.IsTrue(b.Count() > 0, "File is empty");

            string content = f.getFileDataString();
            Assert.IsTrue(content.Length > 0, "File is empty");

            MultipartContent multiPart = f.AsMultipart();
            Assert.IsTrue(multiPart.Headers.Count() > 0, "Multipart not populated");
            f.Dispose();

            if (File.Exists(tmpFile)) {
                File.Delete(tmpFile);
            }
        }
示例#13
0
        public void SyntaxDependencies_File_Test()
        {
            _mockHttp.When(_testUrl + "syntax/dependencies")
                .Respond("application/json", "{'response': 'OK'}");

            RosetteFile f = new RosetteFile(_tmpFile);
            SyntaxDependenciesResponse response = _rosetteApi.SyntaxDependencies(f);
            #pragma warning disable 618
            Assert.AreEqual(response.Content["response"], "OK");
            #pragma warning restore 618
        }