Beispiel #1
0
 /// <summary>
 /// Equals override
 /// </summary>
 /// <param name="obj">The object to compare against</param>
 /// <returns>True if equal</returns>
 public override bool Equals(object obj)
 {
     if (obj is EntityID)
     {
         EntityID    other      = obj as EntityID;
         List <bool> conditions = new List <bool>()
         {
             this.ID != null && other.ID != null?this.ID.Equals(other.ID) : this.ID == other.ID,
                 this.GetHashCode() == other.GetHashCode()
         };
         return(conditions.All(condition => condition));
     }
     else
     {
         return(false);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Creates a CategoriesResponse from the API's raw output
        /// </summary>
        /// <param name="apiResult">The API's raw output</param>
        public EntitiesResponse(HttpResponseMessage apiResult) : base(apiResult)
        {
            List <RosetteEntity> entities = new List <RosetteEntity>();
            JArray enumerableResults      = this.ContentDictionary.ContainsKey(entitiesKey) ? this.ContentDictionary[entitiesKey] as JArray : new JArray();

            foreach (JObject result in enumerableResults)
            {
                String         type        = result.Properties().Where((p) => String.Equals(p.Name, typeKey, StringComparison.OrdinalIgnoreCase)).Any() ? result[typeKey].ToString() : null;
                String         mention     = result.Properties().Where((p) => String.Equals(p.Name, mentionKey, StringComparison.OrdinalIgnoreCase)).Any() ? result[mentionKey].ToString() : null;
                String         entityIDStr = result.Properties().Where((p) => String.Equals(p.Name, entityIDKey, StringComparison.OrdinalIgnoreCase)).Any() ? result[entityIDKey].ToString() : null;
                EntityID       entityID    = entityIDStr != null ? new EntityID(entityIDStr) : null;
                String         normalized  = result.Properties().Where((p) => String.Equals(p.Name, normalizedKey, StringComparison.OrdinalIgnoreCase)).Any() ? result[normalizedKey].ToString() : null;
                Nullable <int> count       = result.Properties().Where((p) => String.Equals(p.Name, countKey)).Any() ? result[countKey].ToObject <int?>() : null;
                entities.Add(new RosetteEntity(mention, normalized, entityID, type, count));
            }
            this.Entities = entities;
        }
Beispiel #3
0
 /// <summary>
 /// Creates an argument from its position and components.
 /// </summary>
 /// <param name="position">The position of the argument in relation to other arguments.</param>
 /// <param name="argument">The mention of the argument.</param>
 /// <param name="id">The id of the argument.</param>
 public Argument(int position, string argument, EntityID id)
 {
     this.Mention  = argument;
     this.Position = position;
     this.ID       = id;
 }
 /// <summary>
 /// Creates an argument from its position and components.
 /// </summary>
 /// <param name="position">The position of the argument in relation to other arguments.</param>
 /// <param name="argument">The mention of the argument.</param>
 /// <param name="id">The id of the argument.</param>
 public Argument(int position, string argument, EntityID id)
 {
     this.Mention = argument;
     this.Position = position;
     this.ID = id;
 }
 /// <summary>
 /// Creates an entity that has a sentiment associated with it
 /// </summary>
 /// <param name="mention">The mention of the entity</param>
 /// <param name="normalizedMention">The normalized mention of the entity</param>
 /// <param name="id">The contextual ID of the entity to compare it against other entities</param>
 /// <param name="entityType">The entity type</param>
 /// <param name="count">The number of times the entity appeared in the text</param>
 /// <param name="sentiment">The contextual sentiment of the entity</param>
 /// <param name="confidence">The confidence that the sentiment was correctly identified</param>
 public RosetteSentimentEntity(String mention, String normalizedMention, EntityID id, String entityType, Nullable <int> count, String sentiment, Nullable <decimal> confidence) : base(mention, normalizedMention, id, entityType, count)
 {
     this.Sentiment = new SentimentResponse.RosetteSentiment(sentiment, confidence);
 }
 /// <summary>
 /// Creates an entity that has a sentiment associated with it
 /// </summary>
 /// <param name="mention">The mention of the entity</param>
 /// <param name="normalizedMention">The normalized mention of the entity</param>
 /// <param name="id">The contextual ID of the entity to compare it against other entities</param>
 /// <param name="entityType">The entity type</param>
 /// <param name="count">The number of times the entity appeared in the text</param>
 /// <param name="sentiment">The contextual sentiment of the entity</param>
 /// <param name="confidence">The confidence that the sentiment was correctly identified</param>
 public RosetteSentimentEntity(String mention, String normalizedMention, EntityID id, String entityType, Nullable<int> count, String sentiment, Nullable<decimal> confidence)
     : base(mention, normalizedMention, id, entityType, count)
 {
     this.Sentiment = new SentimentResponse.RosetteSentiment(sentiment, confidence);
 }
Beispiel #7
0
 /// <summary>
 /// Creates an entity
 /// </summary>
 /// <param name="mention">The mention of the entity</param>
 /// <param name="normalizedMention">The normalzied form of the mention</param>
 /// <param name="id">The mention's id</param>
 /// <param name="entityType">The entity type</param>
 /// <param name="count">The number of times this entity appeared in the input to the API</param>
 public RosetteEntity(String mention, String normalizedMention, EntityID id, String entityType, Nullable<int> count)
 {
     this.Mention = mention;
     this.NormalizedMention = normalizedMention;
     this.ID = id;
     this.Count = count;
     this.EntityType = entityType;
 }
 public void EntityIDTestPassOnCreate()
 {
     EntityID pass = new EntityID("Q1");
     pass.ID = "Q1";
     Assert.AreEqual("https://en.wikipedia.org/wiki/Universe", pass.GetWikipedaURL());
 }
 public void EntityIDTestLinkValidOnSet()
 {
     EntityID tidAtFirst = new EntityID("T423");
     Assert.AreEqual(null, tidAtFirst.GetWikipedaURL());
     tidAtFirst.ID = "Q2";
     Assert.AreEqual("https://en.wikipedia.org/wiki/Earth", tidAtFirst.GetWikipedaURL());
 }
 public void EntityIDLinkNullOnSetToNull()
 {
     EntityID eid = new EntityID(null);
     Assert.AreEqual(null, eid.GetWikipedaURL());
 }