Exemplo n.º 1
0
        public void FirstCharacter()
        {
            var users = MentionExtractor.ExtractMentions("@foo");

            Assert.Equal(1, users.Count);
            Assert.Equal("foo", users[0]);
        }
Exemplo n.º 2
0
        private void AddMentions(ChatMessage message)
        {
            bool anyMentions = false;

            foreach (var userName in MentionExtractor.ExtractMentions(message.Content))
            {
                ChatUser mentionedUser = _repository.GetUserByName(userName);

                // Don't create a mention if
                // 1. If the mentioned user doesn't exist.
                // 2. If you mention yourself
                // 3. If you're mentioned in a private room that you don't have access to
                if (mentionedUser == null ||
                    mentionedUser == message.User ||
                    (message.Room.Private && !mentionedUser.AllowedRooms.Contains(message.Room)))
                {
                    continue;
                }

                anyMentions = true;

                // Mark the notification as read if the user is online
                bool markAsRead = mentionedUser.Status == (int)UserStatus.Active;

                _service.AddNotification(mentionedUser, message, markAsRead);
            }

            if (anyMentions)
            {
                _repository.CommitChanges();
            }
        }
Exemplo n.º 3
0
        public void TrailingSpace()
        {
            var users = MentionExtractor.ExtractMentions("@foo ");

            Assert.Equal(1, users.Count);
            Assert.Equal("foo", users[0]);
        }
Exemplo n.º 4
0
        public void Multiple()
        {
            var users = MentionExtractor.ExtractMentions("@foo @bar");

            Assert.Equal(2, users.Count);
            Assert.Equal("foo", users[0]);
            Assert.Equal("bar", users[1]);
        }
Exemplo n.º 5
0
        public List <EntityInfo> ExtractMentionsOrLists(string text)
        {
            var result = new List <EntityInfo>();

            if (!string.IsNullOrEmpty(text))
            {
                MentionExtractor.Extract(text, true, result);
            }
            return(result);
        }
Exemplo n.º 6
0
        public List <EntityInfo> ExtractMentionedScreenNames(string text)
        {
            var result = new List <EntityInfo>();

            if (!string.IsNullOrEmpty(text))
            {
                MentionExtractor.Extract(text, false, result);
            }
            return(result);
        }
Exemplo n.º 7
0
        public List <EntityInfo> ExtractEntities(string text)
        {
            var result = new List <EntityInfo>();

            if (!string.IsNullOrEmpty(text))
            {
                UrlExtractor.Extract(text, this.ExtractsUrlWithoutProtocol, this._tldDictionary, this._longestTldLength, this._shortestTldLength, result);
                HashtagExtractor.Extract(text, result);
                MentionExtractor.Extract(text, true, result);
                CashtagExtractor.Extract(text, result);
                RemoveOverlappingEntities(result);
            }
            return(result);
        }
Exemplo n.º 8
0
        private void AddMentions(ChatMessage message)
        {
            var mentionedUsers = new List <ChatUser>();

            foreach (var userName in MentionExtractor.ExtractMentions(message.Content))
            {
                ChatUser mentionedUser = _repository.GetUserByName(userName);

                // Don't create a mention if
                // 1. If the mentioned user doesn't exist.
                // 2. If you mention yourself
                // 3. If you're mentioned in a private room that you don't have access to
                // 4. You've already been mentioned in this message
                if (mentionedUser == null ||
                    mentionedUser == message.User ||
                    (message.Room.Private && !mentionedUser.AllowedRooms.Contains(message.Room)) ||
                    mentionedUsers.Contains(mentionedUser))
                {
                    continue;
                }

                // mark as read if ALL of the following
                // 1. user is not offline
                // 2. user is not AFK
                // 3. user has been active within the last 10 minutes
                // 4. user is currently in the room
                bool markAsRead = mentionedUser.Status != (int)UserStatus.Offline &&
                                  !mentionedUser.IsAfk &&
                                  (DateTimeOffset.UtcNow - mentionedUser.LastActivity) < TimeSpan.FromMinutes(10) &&
                                  _repository.IsUserInRoom(_cache, mentionedUser, message.Room);

                _service.AddNotification(mentionedUser, message, message.Room, markAsRead);

                mentionedUsers.Add(mentionedUser);
            }

            if (mentionedUsers.Count > 0)
            {
                _repository.CommitChanges();
            }

            foreach (var user in mentionedUsers)
            {
                UpdateUnreadMentions(user);
            }
        }
Exemplo n.º 9
0
 public DeterministicCorefAnnotator(Properties props)
 {
     // for backward compatibility
     try
     {
         corefSystem      = new SieveCoreferenceSystem(props);
         mentionExtractor = new MentionExtractor(corefSystem.Dictionaries(), corefSystem.Semantics());
         OldFormat        = bool.Parse(props.GetProperty("oldCorefFormat", "false"));
         allowReparsing   = PropertiesUtils.GetBool(props, Constants.AllowReparsingProp, Constants.AllowReparsing);
         // unless custom mention detection is set, just use the default coref mention detector
         performMentionDetection = !PropertiesUtils.GetBool(props, "dcoref.useCustomMentionDetection", false);
         if (performMentionDetection)
         {
             mentionAnnotator = new CorefMentionAnnotator(props);
         }
     }
     catch (Exception e)
     {
         log.Error("cannot create DeterministicCorefAnnotator!");
         log.Error(e);
         throw new Exception(e);
     }
 }
Exemplo n.º 10
0
        public void Nothing()
        {
            var users = MentionExtractor.ExtractMentions("@@@@@");

            Assert.Equal(0, users.Count);
        }
Exemplo n.º 11
0
 public virtual void Annotate(Annotation annotation)
 {
     // temporarily set the primary named entity tag to the coarse tag
     SetNamedEntityTagGranularity(annotation, "coarse");
     if (performMentionDetection)
     {
         mentionAnnotator.Annotate(annotation);
     }
     try
     {
         IList <Tree> trees = new List <Tree>();
         IList <IList <CoreLabel> > sentences = new List <IList <CoreLabel> >();
         // extract trees and sentence words
         // we are only supporting the new annotation standard for this Annotator!
         bool hasSpeakerAnnotations = false;
         if (annotation.ContainsKey(typeof(CoreAnnotations.SentencesAnnotation)))
         {
             // int sentNum = 0;
             foreach (ICoreMap sentence in annotation.Get(typeof(CoreAnnotations.SentencesAnnotation)))
             {
                 IList <CoreLabel> tokens = sentence.Get(typeof(CoreAnnotations.TokensAnnotation));
                 sentences.Add(tokens);
                 Tree tree = sentence.Get(typeof(TreeCoreAnnotations.TreeAnnotation));
                 trees.Add(tree);
                 SemanticGraph dependencies = SemanticGraphFactory.MakeFromTree(tree, SemanticGraphFactory.Mode.Collapsed, GrammaticalStructure.Extras.None, null, true);
                 // locking here is crucial for correct threading!
                 sentence.Set(typeof(SemanticGraphCoreAnnotations.AlternativeDependenciesAnnotation), dependencies);
                 if (!hasSpeakerAnnotations)
                 {
                     // check for speaker annotations
                     foreach (CoreLabel t in tokens)
                     {
                         if (t.Get(typeof(CoreAnnotations.SpeakerAnnotation)) != null)
                         {
                             hasSpeakerAnnotations = true;
                             break;
                         }
                     }
                 }
                 MentionExtractor.MergeLabels(tree, tokens);
                 MentionExtractor.InitializeUtterance(tokens);
             }
         }
         else
         {
             log.Error("this coreference resolution system requires SentencesAnnotation!");
             return;
         }
         if (hasSpeakerAnnotations)
         {
             annotation.Set(typeof(CoreAnnotations.UseMarkedDiscourseAnnotation), true);
         }
         // extract all possible mentions
         // this is created for each new annotation because it is not threadsafe
         RuleBasedCorefMentionFinder finder = new RuleBasedCorefMentionFinder(allowReparsing);
         IList <IList <Mention> >    allUnprocessedMentions = finder.ExtractPredictedMentions(annotation, 0, corefSystem.Dictionaries());
         // add the relevant info to mentions and order them for coref
         Document document = mentionExtractor.Arrange(annotation, sentences, trees, allUnprocessedMentions);
         IList <IList <Mention> >      orderedMentions = document.GetOrderedMentions();
         IDictionary <int, CorefChain> result          = corefSystem.CorefReturnHybridOutput(document);
         annotation.Set(typeof(CorefCoreAnnotations.CorefChainAnnotation), result);
         if (OldFormat)
         {
             IDictionary <int, CorefChain> oldResult = corefSystem.Coref(document);
             AddObsoleteCoreferenceAnnotations(annotation, orderedMentions, oldResult);
         }
     }
     catch (Exception e)
     {
         throw;
     }
     catch (Exception e)
     {
         throw new Exception(e);
     }
     finally
     {
         // restore to the fine-grained
         SetNamedEntityTagGranularity(annotation, "fine");
     }
 }