コード例 #1
0
        /// <summary>
        /// Method to show GetMentionsActivity.
        /// </summary>
        /// <param name="scrumMembers">Scrum members present in the current scrum.</param>
        /// <returns>member ids.</returns>
        private Activity GetMentionsActivity(IEnumerable <TeamsChannelAccount> scrumMembers)
        {
            StringBuilder membersMention = new StringBuilder();
            var           entities       = new List <Entity>();
            var           mentions       = new List <Mention>();

            foreach (var member in scrumMembers)
            {
                membersMention.Append(" ");
                var mention = new Mention
                {
                    Mentioned = new ChannelAccount()
                    {
                        Id   = member.Id,
                        Name = member.Name,
                    },
                    Text = $"<at>{XmlConvert.EncodeName(member.Name)}</at>",
                };
                mentions.Add(mention);
                entities.Add(mention);
                membersMention.Append(mention.Text).Append(",").Append(" ");
            }

            membersMention = membersMention.Insert(0, "CC: ");
            var replyActivity = MessageFactory.Text(membersMention.ToString().Trim().TrimEnd(','));

            replyActivity.Entities = entities;
            return(replyActivity);
        }
コード例 #2
0
        internal static string GetMessageForUser(Mention userMention)
        {
            var user = Users[userMention.Text];

            var template = @"Hey {0} It looks like you're typing some code. Let me run it for you! 😊";

            if (user.CodeSubmissionCount < 3)
            {
                template = GetMessageTemplate(Level1MessageTemplates);
            }
            else
            {
                var split = Random.NextDouble();

                if (split > 5)
                {
                    split = Random.NextDouble();
                    if (user.HasCustomTemplates && split > 7)
                    {
                        template = user.GetMessageTemplate();
                    }
                    else
                    {
                        template = GetMessageTemplate(Level2MessageTemplates);
                    }
                }
                else
                {
                    template = GetMessageTemplate(Level1MessageTemplates);
                }
            }

            return(GenerateMessage(userMention, template));
        }
コード例 #3
0
        public void RemoveRecipientMention_forTeams()
        {
            var activity = CreateActivity();

            activity.Text = "<at>firstName</at> lastName\n";
            var expectedStrippedName = "lastName";

            var mention = new Mention
            {
                Mentioned = new ChannelAccount()
                {
                    Id   = activity.Recipient.Id,
                    Name = "firstName",
                },
                Text = null,
                Type = "mention",
            };
            var lst = new List <Entity>();

            var output = JsonConvert.SerializeObject(mention);
            var entity = JsonConvert.DeserializeObject <Entity>(output);

            lst.Add(entity);
            activity.Entities = lst;

            var strippedActivityText = activity.RemoveRecipientMention();

            Assert.AreEqual(strippedActivityText, expectedStrippedName);
        }
コード例 #4
0
        public static bool IsPleonasticDebug(Mention m, Tree tree, StringBuilder sbLog)
        {
            if (!Sharpen.Runtime.EqualsIgnoreCase(m.SpanToString(), "it"))
            {
                return(false);
            }
            bool isPleonastic   = false;
            int  patternIdx     = -1;
            int  matchedPattern = -1;

            foreach (TregexPattern p in pleonasticPatterns)
            {
                patternIdx++;
                if (CheckPleonastic(m, tree, p))
                {
                    // SieveCoreferenceSystem.logger.fine("RuleBasedCorefMentionFinder: matched pleonastic pattern '" + p + "' for " + tree);
                    isPleonastic   = true;
                    matchedPattern = patternIdx;
                }
            }
            sbLog.Append("PLEONASTIC IT: mention ID: " + m.mentionID + "\thastwin: " + m.hasTwin + "\tpleonastic it? " + isPleonastic + "\tcorrect? " + (m.hasTwin != isPleonastic) + "\tmatched pattern: " + matchedPattern + "\n");
            sbLog.Append(m.contextParseTree.PennString()).Append("\n");
            sbLog.Append("PLEONASTIC IT END\n");
            return(isPleonastic);
        }
コード例 #5
0
        public async Task OnTurnAsync(ITurnContext turnContext, NextDelegate next, CancellationToken cancellationToken)
        {
            if (turnContext.Activity.Conversation.IsGroup == true)
            {
                turnContext.OnSendActivities(async(ctx, activities, nextSend) =>
                {
                    foreach (var activity in activities)
                    {
                        var text      = $"<at>{activity.Recipient.Name}</at>";
                        var mention   = new Mention(activity.Recipient, text, "mention");
                        activity.Text = text + activity.Text;
                        if (activity.Entities == null)
                        {
                            activity.Entities = new List <Entity>();
                        }
                        activity.Entities.Add(mention);
                    }

                    // run full pipeline
                    var responses = await nextSend().ConfigureAwait(false);
                    return(responses);
                });

                turnContext.Activity.RemoveRecipientMention();
            }

            await next(cancellationToken);
        }
コード例 #6
0
        internal async void InitAllList()
        {
#pragma warning disable CS4014 // 由于此调用不会等待,因此在调用完成前将继续执行当前方法
            GetUnreadCount();
            Timeline.Refresh();
            if (Settings.IsMergeMentionAndComment)
            {
                MergeMessage.Refresh();
            }
            else
            {
                Mention.Refresh();
                Comment.Refresh();
                CommentMention.Refresh();
            }
            Favor.Refresh();
            Message.Refresh();
#pragma warning restore CS4014 // 由于此调用不会等待,因此在调用完成前将继续执行当前方法
            try
            {
                (await Core.Api.Friendships.Groups.GetGroups()).Lists.ForEach(item => Groups.Add(item));
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Groups)));
            }
            catch (Exception ex) when(ex is WebException || ex is HttpRequestException || ex is TaskCanceledException || ex is NullReferenceException)
            {
            }
        }
コード例 #7
0
        public static LocalEmbed CreateInfoEmbed(this CachedGuild guild)
        {
            var e = new LocalEmbed()
                    .WithDefaultColor()
                    .WithTitle(guild.Name)
                    .WithThumbnailUrl(guild.GetIconUrl());

            if (guild.Description is not null)
            {
                e.WithDescription(guild.Description);
            }

            e.AddInlineField("Owner", Mention.User(guild.OwnerId));

            e.AddInlineField("Created On", Markdown.Timestamp(guild.CreatedAt()));
            e.FillLineWithEmptyFields();

            e.AddInlineField("Member Count", guild.MemberCount);
            e.AddInlineField("Role Count", guild.Roles.Count);

            var channels = guild.GetChannels();

            e.AddInlineField("Channel Count", channels.Count);

            e.AddInlineField("Text Channel Count", channels.Count(x => x.Value is CachedTextChannel));
            e.AddInlineField("Voice Channel Count", channels.Count(x => x.Value is CachedVoiceChannel));
            e.AddInlineField("Category Count", channels.Count(x => x.Value is CachedCategoryChannel));

            e.AddInlineField("Boost Level", guild.BoostTier);
            e.AddInlineField("Emoji Count", guild.Emojis.Count);
            e.AddInlineField("Locale", guild.PreferredLocale);

            return(e);
        }
コード例 #8
0
        /// <summary>
        /// Method to show GetMentionsActivity.
        /// </summary>
        /// <param name="turnContext">Context object containing information cached for a single turn of conversation with a user.</param>
        /// <param name="scrumMasterDetails">Scrum master details.</param>
        /// <param name="cancellationToken">Propagates notification that operations should be canceled.</param>
        /// <returns>member ids.</returns>
        private async Task <Activity> GetMentionsActivityAsync(ITurnContext turnContext, ScrumMaster scrumMasterDetails, CancellationToken cancellationToken)
        {
            var members = await this.scrumHelper.GetValidMembersInScrumAsync(turnContext, scrumMasterDetails, cancellationToken);

            StringBuilder membersMention = new StringBuilder();
            var           entities       = new List <Entity>();
            var           mentions       = new List <Mention>();

            foreach (var member in members)
            {
                membersMention.Append(" ");
                var mention = new Mention
                {
                    Mentioned = new ChannelAccount()
                    {
                        Id   = member.Id,
                        Name = member.Name,
                    },
                    Text = $"<at>{XmlConvert.EncodeName(member.Name)}</at>",
                };
                mentions.Add(mention);
                entities.Add(mention);
                membersMention.Append(mention.Text).Append(",").Append(" ");
            }

            membersMention = membersMention.Insert(0, "CC: ");
            var replyActivity = MessageFactory.Text(membersMention.ToString().Trim().TrimEnd(','));

            replyActivity.Entities = entities;
            return(replyActivity);
        }
コード例 #9
0
        /// <summary>Divides a sentence into clauses and sort the antecedents for pronoun matching</summary>
        private static IList <Mention> SortMentionsByClause(IList <Mention> l, Mention m1)
        {
            IList <Mention> sorted  = new List <Mention>();
            Tree            tree    = m1.contextParseTree;
            Tree            current = m1.mentionSubTree;

            if (tree == null || current == null)
            {
                return(l);
            }
            while (true)
            {
                current = current.Ancestor(1, tree);
                string curLabel = current.Label().Value();
                if ("TOP".Equals(curLabel) || curLabel.StartsWith("S") || curLabel.Equals("NP"))
                {
                    //      if(current.label().value().startsWith("S")){
                    foreach (Mention m in l)
                    {
                        if (!sorted.Contains(m) && current.Dominates(m.mentionSubTree))
                        {
                            sorted.Add(m);
                        }
                    }
                }
                if (current.Ancestor(1, tree) == null)
                {
                    break;
                }
            }
            return(sorted);
        }
コード例 #10
0
        public static IList <Mention> GetOrderedAntecedents(Mention m, int antecedentSentence, int mPosition, IList <IList <Mention> > orderedMentionsBySentence, Dictionaries dict)
        {
            IList <Mention> orderedAntecedents = new List <Mention>();

            // ordering antecedents
            if (antecedentSentence == m.sentNum)
            {
                // same sentence
                Sharpen.Collections.AddAll(orderedAntecedents, orderedMentionsBySentence[m.sentNum].SubList(0, mPosition));
                if (dict.relativePronouns.Contains(m.SpanToString()))
                {
                    Java.Util.Collections.Reverse(orderedAntecedents);
                }
                else
                {
                    orderedAntecedents = SortMentionsByClause(orderedAntecedents, m);
                }
            }
            else
            {
                // previous sentence
                Sharpen.Collections.AddAll(orderedAntecedents, orderedMentionsBySentence[antecedentSentence]);
            }
            return(orderedAntecedents);
        }
コード例 #11
0
        public override bool CheckEntityMatch(Document document, CorefCluster mentionCluster, CorefCluster potentialAntecedent, Dictionaries dict, ICollection <Mention> roleSet)
        {
            bool    matched     = false;
            Mention mainMention = mentionCluster.GetRepresentativeMention();
            Mention antMention  = potentialAntecedent.GetRepresentativeMention();

            // Check if the representative mentions are compatible
            if (IsNamedMention(mainMention, dict, roleSet) && IsNamedMention(antMention, dict, roleSet))
            {
                if (mainMention.originalSpan.Count > minTokens || antMention.originalSpan.Count > minTokens)
                {
                    if (CorefRules.EntityAttributesAgree(mentionCluster, potentialAntecedent, ignoreGender))
                    {
                        if (supportedNerTypes.Contains(mainMention.nerString) || supportedNerTypes.Contains(antMention.nerString))
                        {
                            matched = mentionMatcher.IsCompatible(mainMention, antMention);
                            if (matched != null)
                            {
                                //Redwood.log("Match '" + mainMention + "' with '" + antMention + "' => " + matched);
                                if (!matched)
                                {
                                    document.AddIncompatible(mainMention, antMention);
                                }
                            }
                            else
                            {
                                matched = false;
                            }
                        }
                    }
                }
            }
            return(matched);
        }
コード例 #12
0
ファイル: SqlInterface.cs プロジェクト: melnx/Bermuda
        private void AddMention(Mention mention)
        {
            if (!ReferenceEquals(Mentions.AddOrUpdate(mention.Id, mention, (x, y) => y), mention))
            {
                return;
            }

            ConcurrentDictionary <long, long> tagLookup;

            if (MentionTagLookup.TryGetValue(mention.Id, out tagLookup))
            {
                mention.Tags = tagLookup.Select(x => x.Key).ToList();
            }

            ConcurrentDictionary <long, long> datasourceLookup;

            if (MentionDatasourceLookup.TryGetValue(mention.Id, out datasourceLookup))
            {
                mention.Datasources = datasourceLookup.Select(x => x.Key).ToList();
            }

            ConcurrentDictionary <long, long> themeLookup;

            if (MentionThemeLookup.TryGetValue(mention.Id, out themeLookup))
            {
                mention.Themes = themeLookup.Select(x => x.Value).ToList();
            }
        }
コード例 #13
0
        protected internal static void ExtractEnumerations(ICoreMap s, IList <Mention> mentions, ICollection <IntPair> mentionSpanSet, ICollection <IntPair> namedEntitySpanSet)
        {
            IList <CoreLabel> sent     = s.Get(typeof(CoreAnnotations.TokensAnnotation));
            Tree          tree         = s.Get(typeof(TreeCoreAnnotations.TreeAnnotation));
            SemanticGraph dependency   = s.Get(typeof(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation));
            TregexPattern tgrepPattern = enumerationsMentionPattern;
            TregexMatcher matcher      = tgrepPattern.Matcher(tree);
            IDictionary <IntPair, Tree> spanToMentionSubTree = Generics.NewHashMap();

            while (matcher.Find())
            {
                matcher.GetMatch();
                Tree         m1       = matcher.GetNode("m1");
                Tree         m2       = matcher.GetNode("m2");
                IList <Tree> mLeaves  = m1.GetLeaves();
                int          beginIdx = ((CoreLabel)mLeaves[0].Label()).Get(typeof(CoreAnnotations.IndexAnnotation)) - 1;
                int          endIdx   = ((CoreLabel)mLeaves[mLeaves.Count - 1].Label()).Get(typeof(CoreAnnotations.IndexAnnotation));
                spanToMentionSubTree[new IntPair(beginIdx, endIdx)] = m1;
                mLeaves  = m2.GetLeaves();
                beginIdx = ((CoreLabel)mLeaves[0].Label()).Get(typeof(CoreAnnotations.IndexAnnotation)) - 1;
                endIdx   = ((CoreLabel)mLeaves[mLeaves.Count - 1].Label()).Get(typeof(CoreAnnotations.IndexAnnotation));
                spanToMentionSubTree[new IntPair(beginIdx, endIdx)] = m2;
            }
            foreach (IntPair mSpan in spanToMentionSubTree.Keys)
            {
                if (!mentionSpanSet.Contains(mSpan) && !InsideNE(mSpan, namedEntitySpanSet))
                {
                    int     dummyMentionId = -1;
                    Mention m = new Mention(dummyMentionId, mSpan.Get(0), mSpan.Get(1), dependency, new List <CoreLabel>(sent.SubList(mSpan.Get(0), mSpan.Get(1))), spanToMentionSubTree[mSpan]);
                    mentions.Add(m);
                    mentionSpanSet.Add(mSpan);
                }
            }
        }
コード例 #14
0
 private static string GetRole(Mention m)
 {
     if (m.isSubject)
     {
         return("subject");
     }
     else
     {
         if (m.isDirectObject)
         {
             return("direct-object");
         }
         else
         {
             if (m.isIndirectObject)
             {
                 return("indirect-object");
             }
             else
             {
                 if (m.isPrepositionObject)
                 {
                     return("preposition-object");
                 }
             }
         }
     }
     return("unknown");
 }
コード例 #15
0
        public virtual IList <IList <Mention> > ExtractGoldMentions(CoNLL2011DocumentReader.Document conllDoc)
        {
            IList <ICoreMap>         sentences                   = conllDoc.GetAnnotation().Get(typeof(CoreAnnotations.SentencesAnnotation));
            IList <IList <Mention> > allGoldMentions             = new List <IList <Mention> >();
            CollectionValuedMap <string, ICoreMap> corefChainMap = conllDoc.GetCorefChainMap();

            for (int i = 0; i < sentences.Count; i++)
            {
                allGoldMentions.Add(new List <Mention>());
            }
            int maxCorefClusterId = -1;

            foreach (string corefIdStr in corefChainMap.Keys)
            {
                int id = System.Convert.ToInt32(corefIdStr);
                if (id > maxCorefClusterId)
                {
                    maxCorefClusterId = id;
                }
            }
            int newMentionID = maxCorefClusterId + 1;

            foreach (KeyValuePair <string, ICollection <ICoreMap> > idChainEntry in corefChainMap)
            {
                int id = System.Convert.ToInt32(idChainEntry.Key);
                int clusterMentionCnt = 0;
                foreach (ICoreMap m in idChainEntry.Value)
                {
                    clusterMentionCnt++;
                    Mention mention = new Mention();
                    mention.goldCorefClusterID = id;
                    if (clusterMentionCnt == 1)
                    {
                        // First mention in cluster
                        mention.mentionID   = id;
                        mention.originalRef = -1;
                    }
                    else
                    {
                        mention.mentionID   = newMentionID;
                        mention.originalRef = id;
                        newMentionID++;
                    }
                    if (maxID < mention.mentionID)
                    {
                        maxID = mention.mentionID;
                    }
                    int      sentIndex = m.Get(typeof(CoreAnnotations.SentenceIndexAnnotation));
                    ICoreMap sent      = sentences[sentIndex];
                    mention.startIndex = m.Get(typeof(CoreAnnotations.TokenBeginAnnotation)) - sent.Get(typeof(CoreAnnotations.TokenBeginAnnotation));
                    mention.endIndex   = m.Get(typeof(CoreAnnotations.TokenEndAnnotation)) - sent.Get(typeof(CoreAnnotations.TokenBeginAnnotation));
                    // will be set by arrange
                    mention.originalSpan = m.Get(typeof(CoreAnnotations.TokensAnnotation));
                    // Mention dependency graph is the enhanced dependency graph of the sentence
                    mention.dependency = sentences[sentIndex].Get(typeof(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation));
                    allGoldMentions[sentIndex].Add(mention);
                }
            }
            return(allGoldMentions);
        }
コード例 #16
0
 /// <summary>initialize positions and corefClusters (put each mention in each CorefCluster)</summary>
 private void InitializeCorefCluster()
 {
     for (int i = 0; i < predictedOrderedMentionsBySentence.Count; i++)
     {
         for (int j = 0; j < predictedOrderedMentionsBySentence[i].Count; j++)
         {
             Mention m = predictedOrderedMentionsBySentence[i][j];
             if (allPredictedMentions.Contains(m.mentionID))
             {
                 SieveCoreferenceSystem.logger.Warning("WARNING: Already contain mention " + m.mentionID);
                 Mention m1 = allPredictedMentions[m.mentionID];
                 SieveCoreferenceSystem.logger.Warning("OLD mention: " + m1.SpanToString() + "[" + m1.startIndex + "," + m1.endIndex + "]");
                 SieveCoreferenceSystem.logger.Warning("NEW mention: " + m.SpanToString() + "[" + m.startIndex + "," + m.endIndex + "]");
             }
             //          SieveCoreferenceSystem.debugPrintMentions(System.err, "PREDICTED ORDERED", predictedOrderedMentionsBySentence);
             //          SieveCoreferenceSystem.debugPrintMentions(System.err, "GOLD ORDERED", goldOrderedMentionsBySentence);
             System.Diagnostics.Debug.Assert((!allPredictedMentions.Contains(m.mentionID)));
             allPredictedMentions[m.mentionID] = m;
             IntTuple pos = new IntTuple(2);
             pos.Set(0, i);
             pos.Set(1, j);
             positions[m] = pos;
             m.sentNum    = i;
             System.Diagnostics.Debug.Assert((!corefClusters.Contains(m.mentionID)));
             corefClusters[m.mentionID] = new CorefCluster(m.mentionID, Generics.NewHashSet(Java.Util.Collections.SingletonList(m)));
             m.corefClusterID           = m.mentionID;
             IntTuple headPosition = new IntTuple(2);
             headPosition.Set(0, i);
             headPosition.Set(1, m.headIndex);
             mentionheadPositions[headPosition] = m;
         }
     }
 }
コード例 #17
0
        /// <summary>Check one mention is the speaker of the other mention</summary>
        public static bool IsSpeaker(Mention m, Mention ant, Dictionaries dict)
        {
            if (!dict.firstPersonPronouns.Contains(ant.SpanToString().ToLower()) || ant.number == Dictionaries.Number.Plural || ant.sentNum != m.sentNum)
            {
                return(false);
            }
            int countQuotationMark = 0;

            for (int i = System.Math.Min(m.headIndex, ant.headIndex) + 1; i < System.Math.Max(m.headIndex, ant.headIndex); i++)
            {
                string word = m.sentenceWords[i].Get(typeof(CoreAnnotations.TextAnnotation));
                if (word.Equals("``") || word.Equals("''"))
                {
                    countQuotationMark++;
                }
            }
            if (countQuotationMark != 1)
            {
                return(false);
            }
            IndexedWord w = m.dependency.GetNodeByWordPattern(m.sentenceWords[m.headIndex].Get(typeof(CoreAnnotations.TextAnnotation)));

            if (w == null)
            {
                return(false);
            }
            foreach (Pair <GrammaticalRelation, IndexedWord> parent in m.dependency.ParentPairs(w))
            {
                if (parent.First().GetShortName().Equals("nsubj") && dict.reportVerb.Contains(parent.Second().Get(typeof(CoreAnnotations.LemmaAnnotation))))
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #18
0
        public virtual void ExtractNPorPRP(ICoreMap s, IList <Mention> mentions, ICollection <IntPair> mentionSpanSet, ICollection <IntPair> namedEntitySpanSet)
        {
            IList <CoreLabel> sent = s.Get(typeof(CoreAnnotations.TokensAnnotation));
            Tree tree = s.Get(typeof(TreeCoreAnnotations.TreeAnnotation));

            tree.IndexLeaves();
            SemanticGraph basicDependency    = s.Get(typeof(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation));
            SemanticGraph enhancedDependency = s.Get(typeof(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation));

            if (enhancedDependency == null)
            {
                enhancedDependency = s.Get(typeof(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation));
            }
            TregexPattern tgrepPattern = npOrPrpMentionPattern;
            TregexMatcher matcher      = tgrepPattern.Matcher(tree);

            while (matcher.Find())
            {
                Tree         t        = matcher.GetMatch();
                IList <Tree> mLeaves  = t.GetLeaves();
                int          beginIdx = ((CoreLabel)mLeaves[0].Label()).Get(typeof(CoreAnnotations.IndexAnnotation)) - 1;
                int          endIdx   = ((CoreLabel)mLeaves[mLeaves.Count - 1].Label()).Get(typeof(CoreAnnotations.IndexAnnotation));
                //if (",".equals(sent.get(endIdx-1).word())) { endIdx--; } // try not to have span that ends with ,
                IntPair mSpan = new IntPair(beginIdx, endIdx);
                if (!mentionSpanSet.Contains(mSpan) && (lang == Locale.Chinese || !InsideNE(mSpan, namedEntitySpanSet)))
                {
                    //      if(!mentionSpanSet.contains(mSpan) && (!insideNE(mSpan, namedEntitySpanSet) || t.value().startsWith("PRP")) ) {
                    int     dummyMentionId = -1;
                    Mention m = new Mention(dummyMentionId, beginIdx, endIdx, sent, basicDependency, enhancedDependency, new List <CoreLabel>(sent.SubList(beginIdx, endIdx)), t);
                    mentions.Add(m);
                    mentionSpanSet.Add(mSpan);
                }
            }
        }
コード例 #19
0
        /// <inheritdoc/>
        public override ValueTask <TypeParserResult <TChannel> > ParseAsync(Parameter parameter, string value, DiscordGuildCommandContext context)
        {
            if (!context.Bot.CacheProvider.TryGetChannels(context.GuildId, out var cache))
            {
                throw new InvalidOperationException($"The {GetType().Name} requires the channel cache.");
            }

            // Wraps the cache in a pattern-matching wrapper dictionary.
            var      channels = new ReadOnlyOfTypeDictionary <Snowflake, CachedGuildChannel, TChannel>(cache);
            TChannel channel;

            if (Snowflake.TryParse(value, out var id) || Mention.TryParseChannel(value, out id))
            {
                // The value is a mention or an id.
                channel = channels.GetValueOrDefault(id);
            }
            else
            {
                // The value is possibly a name.
                channel = channels.Values.FirstOrDefault(x => x.Name == value);
            }

            if (channel != null)
            {
                return(Success(channel));
            }

            return(Failure($"No {ChannelString} found matching the input."));
        }
コード例 #20
0
        private async Task <List <Entity> > GetPeopleToMention(ITurnContext turnContext, CancellationToken cancellationToken)
        {
            IEnumerable <TeamsChannelAccount> members = await TeamsInfo.GetMembersAsync(turnContext, cancellationToken);

            List <Entity> entities = new List <Entity>();

            foreach (TeamsChannelAccount member in members)
            {
                foreach (string upn in dataFromRequest.Mentions)
                {
                    if (String.Compare(member.UserPrincipalName, upn, true) == 0)
                    {
                        // Construct a ChannelAccount Object.
                        ChannelAccount mentionedUser = new ChannelAccount(member.Id, member.Name, member.Role, member.AadObjectId);
                        // Construct a Mention object.
                        var mentionObject = new Mention
                        {
                            Mentioned = mentionedUser,
                            Text      = $"<at>{XmlConvert.EncodeName(member.Name)}</at>",
                        };
                        entities.Add(mentionObject);
                    }
                }
            }
            return(entities);
        }
コード例 #21
0
        /// <summary>Skip this mention? (search pruning)</summary>
        public virtual bool SkipThisMention(Document document, Mention m1, CorefCluster c, Dictionaries dict)
        {
            bool skip = false;

            // only do for the first mention in its cluster
            //    if(!flags.USE_EXACTSTRINGMATCH && !flags.USE_ROLEAPPOSITION && !flags.USE_PREDICATENOMINATIVES
            if (!flags.UseRoleapposition && !flags.UsePredicatenominatives && !flags.UseAcronym && !flags.UseApposition && !flags.UseRelativepronoun && !c.GetFirstMention().Equals(m1))
            {
                // CHINESE CHANGE
                return(true);
            }
            if (m1.appositions == null && m1.predicateNominatives == null && (m1.LowercaseNormalizedSpanString().StartsWith("a ") || m1.LowercaseNormalizedSpanString().StartsWith("an ")) && !flags.UseExactstringmatch)
            {
                skip = true;
            }
            // A noun phrase starting with an indefinite article - unlikely to have an antecedent (e.g. "A commission" was set up to .... )
            if (dict.indefinitePronouns.Contains(m1.LowercaseNormalizedSpanString()))
            {
                skip = true;
            }
            // An indefinite pronoun - unlikely to have an antecedent (e.g. "Some" say that... )
            foreach (string indef in dict.indefinitePronouns)
            {
                if (m1.LowercaseNormalizedSpanString().StartsWith(indef + " "))
                {
                    skip = true;
                    // A noun phrase starting with an indefinite adjective - unlikely to have an antecedent (e.g. "Another opinion" on the topic is...)
                    break;
                }
            }
            return(skip);
        }
コード例 #22
0
        /// <inheritdoc/>
        public override ValueTask <TypeParserResult <IRole> > ParseAsync(Parameter parameter, string value, DiscordGuildCommandContext context)
        {
            if (!context.Bot.CacheProvider.TryGetRoles(context.GuildId, out var roleCache))
            {
                throw new InvalidOperationException($"The {GetType().Name} requires the role cache.");
            }

            IRole role;

            if (Snowflake.TryParse(value, out var id) || Mention.TryParseRole(value, out id))
            {
                // The value is a mention or id.
                role = roleCache.GetValueOrDefault(id);
            }
            else
            {
                // The value is possibly a name.
                role = roleCache.Values.FirstOrDefault(x => x.Name == value);
            }

            if (role != null)
            {
                return(Success(role));
            }

            return(Failure("No role found matching the input."));
        }
コード例 #23
0
        public virtual bool IsIncompatible(Mention m1, Mention m2)
        {
            int mid1 = System.Math.Min(m1.mentionID, m2.mentionID);
            int mid2 = System.Math.Max(m1.mentionID, m2.mentionID);

            return(incompatibles.Contains(mid1, mid2));
        }
コード例 #24
0
        public void MentionInitsWithNoArgs()
        {
            var mention = new Mention();

            Assert.NotNull(mention);
            Assert.IsType <Mention>(mention);
        }
コード例 #25
0
        protected internal static void ExtractNPorPRP(ICoreMap s, IList <Mention> mentions, ICollection <IntPair> mentionSpanSet, ICollection <IntPair> namedEntitySpanSet)
        {
            IList <CoreLabel> sent = s.Get(typeof(CoreAnnotations.TokensAnnotation));
            Tree tree = s.Get(typeof(TreeCoreAnnotations.TreeAnnotation));

            tree.IndexLeaves();
            SemanticGraph dependency   = s.Get(typeof(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation));
            TregexPattern tgrepPattern = npOrPrpMentionPattern;
            TregexMatcher matcher      = tgrepPattern.Matcher(tree);

            while (matcher.Find())
            {
                Tree         t        = matcher.GetMatch();
                IList <Tree> mLeaves  = t.GetLeaves();
                int          beginIdx = ((CoreLabel)mLeaves[0].Label()).Get(typeof(CoreAnnotations.IndexAnnotation)) - 1;
                int          endIdx   = ((CoreLabel)mLeaves[mLeaves.Count - 1].Label()).Get(typeof(CoreAnnotations.IndexAnnotation));
                if (",".Equals(sent[endIdx - 1].Word()))
                {
                    endIdx--;
                }
                // try not to have span that ends with ,
                IntPair mSpan = new IntPair(beginIdx, endIdx);
                if (!mentionSpanSet.Contains(mSpan) && !InsideNE(mSpan, namedEntitySpanSet))
                {
                    int     dummyMentionId = -1;
                    Mention m = new Mention(dummyMentionId, beginIdx, endIdx, dependency, new List <CoreLabel>(sent.SubList(beginIdx, endIdx)), t);
                    mentions.Add(m);
                    mentionSpanSet.Add(mSpan);
                }
            }
        }
コード例 #26
0
        //Find Twitter IDs in twitter messages
        private void FindTwitterIDs(String message)
        {
            var  regex   = new Regex(@"@\w+");
            var  matches = regex.Matches(message);
            bool idExists;

            foreach (var match in matches)
            {
                idExists = false;
                Mention t = new Mention(match.ToString(), 1);
                foreach (Mention tweet in MentionsList)
                {
                    if (tweet.Id.Trim().Equals(t.Id.Trim()))
                    {
                        tweet.Count++;
                        idExists = true;
                        break;
                    }
                }

                if (!idExists)
                {
                    MentionsList.Add(t);
                }
            }
        }
コード例 #27
0
 public override bool CanResolve(Mention.MentionContext mention)
 {
     string firstToken = mention.FirstTokenText.ToLower();
     string firstTokenTag = mention.FirstToken.SyntacticType;
     bool canResolve = mention.HeadTokenTag == "NN" && !IsDefiniteArticle(firstToken, firstTokenTag);
     return canResolve;
 }
コード例 #28
0
 /// <exception cref="System.Exception"/>
 public override void FindCoreferentAntecedent(Mention m, int mIdx, Document document, Dictionaries dict, Properties props, StringBuilder sbLog)
 {
     for (int distance = 0; distance <= m.sentNum; distance++)
     {
         IList <Mention> candidates = document.predictedMentions[m.sentNum - distance];
         foreach (Mention candidate in candidates)
         {
             if (!MatchedMentionType(candidate, aTypeStr) || !MatchedMentionType(m, mTypeStr))
             {
                 continue;
             }
             //        if(!options.mType.contains(m.mentionType) || !options.aType.contains(candidate.mentionType)) continue;
             if (candidate == m)
             {
                 continue;
             }
             if (distance == 0 && m.AppearEarlierThan(candidate))
             {
                 continue;
             }
             // ignore cataphora
             if (Edu.Stanford.Nlp.Coref.Hybrid.Sieve.Sieve.IsReallyCoref(document, m.mentionID, candidate.mentionID))
             {
                 if (m.mentionType == Dictionaries.MentionType.List)
                 {
                     log.Info("LIST MATCHING MENTION : " + m.SpanToString() + "\tANT: " + candidate.SpanToString());
                 }
                 Edu.Stanford.Nlp.Coref.Hybrid.Sieve.Sieve.Merge(document, m.mentionID, candidate.mentionID);
                 return;
             }
         }
     }
 }
コード例 #29
0
ファイル: Program.cs プロジェクト: jomit/BotWorkshop
        static async Task SendMessageInTeamChannelWithMention(ConnectorClient connectorClient, string teamInternalId, string teamsChannelId, string recipientUserPrincipalName, string message)
        {
            var teamMembers = await connectorClient.Conversations.GetConversationMembersAsync(teamInternalId, default);

            var userToMention = teamMembers
                                .Select(channelAccount => JObject.FromObject(channelAccount).ToObject <TeamsChannelAccount>())
                                .First(user => user.UserPrincipalName == recipientUserPrincipalName);

            var mention = new Mention
            {
                Mentioned = userToMention,
                Text      = $"<at>{userToMention.Name}</at>",
            };

            var msgActivity = MessageFactory.Text($"{mention.Text} - {message}");

            msgActivity.Entities = new List <Entity> {
                mention
            };

            var conversationParameters = new ConversationParameters
            {
                IsGroup     = true,
                ChannelData = new TeamsChannelData
                {
                    Channel = new ChannelInfo(teamsChannelId),
                },
                Activity = msgActivity
            };

            await connectorClient.Conversations.CreateConversationAsync(conversationParameters);
        }
コード例 #30
0
        /// <summary>Skip this mention? (search pruning)</summary>
        public virtual bool SkipThisMention(Document document, Mention m1, CorefCluster c, Dictionaries dict)
        {
            bool skip = false;

            // only do for the first mention in its cluster
            if (!flags.UseExactstringmatch && !flags.UseRoleapposition && !flags.UsePredicatenominatives && !flags.UseAcronym && !flags.UseApposition && !flags.UseRelativepronoun && !c.GetFirstMention().Equals(m1))
            {
                return(true);
            }
            SieveCoreferenceSystem.logger.Finest("DOING COREF FOR:\t" + m1.SpanToString());
            if (m1.appositions == null && m1.predicateNominatives == null && (m1.LowercaseNormalizedSpanString().StartsWith("a ") || m1.LowercaseNormalizedSpanString().StartsWith("an ")) && !flags.UseExactstringmatch)
            {
                skip = true;
            }
            // A noun phrase starting with an indefinite article - unlikely to have an antecedent (e.g. "A commission" was set up to .... )
            if (dict.indefinitePronouns.Contains(m1.LowercaseNormalizedSpanString()))
            {
                skip = true;
            }
            // An indefinite pronoun - unlikely to have an antecedent (e.g. "Some" say that... )
            foreach (string indef in dict.indefinitePronouns)
            {
                if (m1.LowercaseNormalizedSpanString().StartsWith(indef + " "))
                {
                    skip = true;
                    // A noun phrase starting with an indefinite adjective - unlikely to have an antecedent (e.g. "Another opinion" on the topic is...)
                    break;
                }
            }
            if (skip)
            {
                SieveCoreferenceSystem.logger.Finest("MENTION SKIPPED:\t" + m1.SpanToString() + "(" + m1.sentNum + ")" + "\toriginalRef: " + m1.originalRef + " in discourse " + m1.headWord.Get(typeof(CoreAnnotations.UtteranceAnnotation)));
            }
            return(skip);
        }
コード例 #31
0
        public static bool RelaxedStringMatch(Mention m1, Mention m2)
        {
            ICollection <string> propers = GetPropers(m1);

            propers.RetainAll(GetPropers(m2));
            return(!propers.IsEmpty());
        }
コード例 #32
0
 /// <summary>
 /// Creates a new entity based on the specified mention and its specified gender and number properties.
 /// </summary>
 /// <param name="mention">
 /// The first mention of this entity.
 /// </param>
 /// <param name="gender">
 /// The gender of this entity.
 /// </param>
 /// <param name="genderProbability">
 /// The probability that the specified gender is correct.
 /// </param>
 /// <param name="number">
 /// The number for this entity.
 /// </param>
 /// <param name="numberProbability">
 /// The probability that the specified number is correct.
 /// </param>
 public DiscourseEntity(Mention.MentionContext mention, Similarity.GenderEnum gender, double genderProbability, Similarity.NumberEnum number, double numberProbability)
     : base(mention)
 {
     mGender = gender;
     mGenderProbability = genderProbability;
     mNumber = number;
     mNumberProbability = numberProbability;
 }
コード例 #33
0
        public override bool CanResolve(Mention.MentionContext mention)
		{
			string firstToken = mention.FirstTokenText.ToLower();
			string firstTokenTag = mention.FirstToken.SyntacticType;
			bool canResolve = mention.HeadTokenTag == PartsOfSpeech.NounSingularOrMass 
                && !IsDefiniteArticle(firstToken, firstTokenTag);
			return canResolve;
		}
コード例 #34
0
 public virtual double GetNonReferentialProbability(Mention.MentionContext mention)
 {
     List<string> features = GetFeatures(mention);
     double probability = mModel.Evaluate(features.ToArray())[mNonReferentialIndex];
     if (mDebugOn)
     {
         System.Console.Error.WriteLine(this + " " + mention.ToText() + " ->  null " + probability + " " + string.Join(",", features.ToArray()));
     }
     return probability;
 }
コード例 #35
0
        protected internal override List<string> GetFeatures(Mention.MentionContext mention, DiscourseEntity entity)
        {
            List<string> features = base.GetFeatures(mention, entity);

            if (entity != null)
            {
                features.AddRange(GetContextFeatures(mention));
                features.AddRange(GetStringMatchFeatures(mention, entity));
            }
            return features;
        }
コード例 #36
0
		protected internal override bool IsExcluded(Mention.MentionContext entityContext, DiscourseEntity discourseEntity)
		{
			if (base.IsExcluded(entityContext, discourseEntity))
			{
				return true;
			}
			else
			{
                Mention.MentionContext currentEntityContext = discourseEntity.LastExtent;
				return (!CanResolve(currentEntityContext) || base.IsExcluded(entityContext, discourseEntity));
			}
		}
コード例 #37
0
 public virtual void AddEvent(Mention.MentionContext context)
 {
     List<string> features = GetFeatures(context);
     if (context.Id == -1)
     {
         mEvents.Add(new SharpEntropy.TrainingEvent(MaximumEntropyResolver.Same, features.ToArray()));
     }
     else
     {
         mEvents.Add(new SharpEntropy.TrainingEvent(MaximumEntropyResolver.Diff, features.ToArray()));
     }
 }
コード例 #38
0
ファイル: Context.cs プロジェクト: gblosser/OpenNlp
        private void Initialize(Mention.IHeadFinder headFinder)
		{
            Mention.IParse head = headFinder.GetLastHead(Parse);
			List<Mention.IParse> tokenList = head.Tokens;
			this.HeadTokenIndex = headFinder.GetHeadIndex(head);
            Mention.IParse headToken = headFinder.GetHeadToken(head);
            _tokens = tokenList.ToArray();
			this.HeadTokenTag = headToken.SyntacticType;
			this.HeadTokenText = headToken.ToString();
			if (PartsOfSpeech.IsNoun(this.HeadTokenTag) && !PartsOfSpeech.IsProperNoun(this.HeadTokenTag))
			{
				this.Synsets = GetSynsetSet(this);
			}
			else
			{
				this.Synsets = new Util.HashSet<string>();
			}
		}
コード例 #39
0
 /// <summary>
 /// Returns the string of "_" delimited tokens for the specified mention.
 /// </summary>
 /// <param name="mention">
 /// The mention.
 /// </param>
 /// <returns>
 /// the string of "_" delimited tokens for the specified mention.
 /// </returns>
 protected internal virtual string GetFeatureString(Mention.MentionContext mention)
 {
     System.Text.StringBuilder output = new System.Text.StringBuilder();
     object[] mentionTokens = mention.Tokens;
     output.Append(mentionTokens[0].ToString());
     for (int currentToken = 1; currentToken < mentionTokens.Length; currentToken++)
     {
         output.Append("_").Append(mentionTokens[currentToken].ToString());
     }
     return output.ToString();
 }
コード例 #40
0
 /// <summary>
 /// Returns distance features for the specified mention and entity.
 /// </summary>
 /// <param name="mention">
 /// The mention.
 /// </param>
 /// <param name="entity">
 /// The entity.
 /// </param>
 /// <returns>
 /// list of distance features for the specified mention and entity.
 /// </returns>
 protected internal virtual List<string> GetDistanceFeatures(Mention.MentionContext mention, DiscourseEntity entity)
 {
     List<string> features = new List<string>();
     Mention.MentionContext currentEntityContext = entity.LastExtent;
     int entityDistance = mention.NounPhraseDocumentIndex - currentEntityContext.NounPhraseDocumentIndex;
     int sentenceDistance = mention.SentenceNumber - currentEntityContext.SentenceNumber;
     int hobbsEntityDistance;
     if (sentenceDistance == 0)
     {
         hobbsEntityDistance = currentEntityContext.NounPhraseSentenceIndex;
     }
     else
     {
         //hobbsEntityDistance = entityDistance - (entities within sentence from mention to end) + (entities within sentence form start to mention)
         //hobbsEntityDistance = entityDistance - (cec.maxNounLocation - cec.getNounPhraseSentenceIndex) + cec.getNounPhraseSentenceIndex;
         hobbsEntityDistance = entityDistance + (2 * currentEntityContext.NounPhraseSentenceIndex) - currentEntityContext.MaxNounPhraseSentenceIndex;
     }
     features.Add("hd=" + hobbsEntityDistance);
     features.Add("de=" + entityDistance);
     features.Add("ds=" + sentenceDistance);
     //features.add("ds=" + sdist + pronoun);
     //features.add("dn=" + cec.sentenceNumber);
     //features.add("ep=" + cec.nounLocation);
     return features;
 }
コード例 #41
0
        public override DiscourseEntity Retain(Mention.MentionContext mention, DiscourseModel discourseModel)
        {
            //System.err.println(this+".retain("+ec+") "+mode);
            if (mResolverMode == ResolverMode.Train)
            {
                DiscourseEntity discourseEntity = null;
                bool referentFound = false;
                bool hasReferentialCandidate = false;
                bool nonReferentFound = false;
                for (int entityIndex = 0; entityIndex < GetNumberEntitiesBack(discourseModel); entityIndex++)
                {
                    DiscourseEntity currentDiscourseEntity = discourseModel.GetEntity(entityIndex);
                    Mention.MentionContext entityMention = currentDiscourseEntity.LastExtent;
                    if (IsOutOfRange(mention, currentDiscourseEntity))
                    {
                        if (mention.Id != -1 && !referentFound)
                        {
                            //System.err.println("retain: Referent out of range: "+ec.toText()+" "+ec.parse.getSpan());
                        }
                        break;
                    }
                    if (IsExcluded(mention, currentDiscourseEntity))
                    {
                        if (ShowExclusions)
                        {
                            if (mention.Id != - 1 && entityMention.Id == mention.Id)
                            {
                                System.Console.Error.WriteLine(this + ".retain: Referent excluded: (" + mention.Id + ") " + mention.ToText() + " " + mention.IndexSpan + " -> (" + entityMention.Id + ") " + entityMention.ToText() + " " + entityMention.Span + " " + this);
                            }
                        }
                    }
                    else
                    {
                        hasReferentialCandidate = true;
                        bool useAsDifferentExample = defaultReferent(currentDiscourseEntity);
                        //if (!sampleSelection || (mention.getId() != -1 && entityMention.getId() == mention.getId()) || (!nonReferentFound && useAsDifferentExample)) {
                        List<string> features = GetFeatures(mention, currentDiscourseEntity);

                        //add Event to Model
                        if (mDebugOn)
                        {
                            System.Console.Error.WriteLine(this + ".retain: " + mention.Id + " " + mention.ToText() + " -> " + entityMention.Id + " " + currentDiscourseEntity);
                        }
                        if (mention.Id != - 1 && entityMention.Id == mention.Id)
                        {
                            referentFound = true;
                            mEvents.Add(new SharpEntropy.TrainingEvent(Same, features.ToArray()));
                            discourseEntity = currentDiscourseEntity;
                            //System.err.println("MaxentResolver.retain: resolved at "+ei);
                            Distances.Add(entityIndex);
                        }
                        else if (!mPairedSampleSelection || (!nonReferentFound && useAsDifferentExample))
                        {
                            nonReferentFound = true;
                            mEvents.Add(new SharpEntropy.TrainingEvent(Diff, features.ToArray()));
                        }
                        //}
                    }
                    if (mPairedSampleSelection && referentFound && nonReferentFound)
                    {
                        break;
                    }
                    if (mPreferFirstReferent && referentFound)
                    {
                        break;
                    }
                }
                // doesn't refer to anything
                if (hasReferentialCandidate)
                {
                    mNonReferentialResolver.AddEvent(mention);
                }
                return discourseEntity;
            }
            else
            {
                return base.Retain(mention, discourseModel);
            }
        }
コード例 #42
0
        /// <summary>
        /// Returns a string for the specified mention with punctuation, honorifics, designators, and determiners removed.
        /// </summary>
        /// <param name="mention">
        /// The mention to be stripped.
        /// </param>
        /// <returns>
        /// a normalized string representation of the specified mention.
        /// </returns>
        protected internal virtual string StripNounPhrase(Mention.MentionContext mention)
        {
            int start = mention.NonDescriptorStart; //start after descriptors

            Mention.IParse[] mentionTokens = mention.TokenParses;
            int end = mention.HeadTokenIndex + 1;
            if (start == end)
            {
                //System.err.println("StripNounPhrase: return null 1");
                return null;
            }
            //strip determiners
            if (mentionTokens[start].SyntacticType == "DT")
            {
                start++;
            }
            if (start == end)
            {
                //System.err.println("StripNounPhrase: return null 2");
                return null;
            }
            //get to first NNP
            string type;
            for (int index = start; index < end; index++)
            {
                type = mentionTokens[start].SyntacticType;
                if (type.StartsWith("NNP"))
                {
                    break;
                }
                start++;
            }
            if (start == end)
            {
                //System.err.println("StripNounPhrase: return null 3");
                return null;
            }
            if (start + 1 != end)
            {
                // don't do this on head words, to keep "U.S."
                //strip off honorifics in begining
                if (Linker.HonorificsPattern.IsMatch(mentionTokens[start].ToString()))
                {
                    start++;
                }
                if (start == end)
                {
                    //System.err.println("StripNounPhrase: return null 4");
                    return null;
                }
                //strip off and honorifics on the end
                if (Linker.DesignatorsPattern.IsMatch(mentionTokens[mentionTokens.Length - 1].ToString()))
                {
                    end--;
                }
            }
            if (start == end)
            {
                //System.err.println("StripNounPhrase: return null 5");
                return null;
            }
            System.Text.StringBuilder strip = new System.Text.StringBuilder();
            for (int i = start; i < end; i++)
            {
                strip.Append(mentionTokens[i].ToString()).Append(" ");
            }
            return strip.ToString().Trim();
        }
コード例 #43
0
 /// <summary>
 /// Returns a list of features for deciding whether the specified mention refers to the specified discourse entity.
 /// </summary>
 /// <param name="mention">
 /// the mention being considers as possibly referential. 
 /// </param>
 /// <param name="entity">
 /// The discourse entity with which the mention is being considered referential.  
 /// </param>
 /// <returns>
 /// a list of features used to predict reference between the specified mention and entity.
 /// </returns>
 protected internal virtual List<string> GetFeatures(Mention.MentionContext mention, DiscourseEntity entity)
 {
     List<string> features = new List<string>();
     features.Add(Default);
     features.AddRange(GetCompatibilityFeatures(mention, entity));
     return features;
 }
コード例 #44
0
 /// <summary>
 /// Excludes entities which you are not compatible with the entity under consideration.  The default 
 /// implementation excludes entties whose last extent contains the extent under consideration.
 /// This prevents posessive pronouns from referring to the noun phrases they modify and other 
 /// undesirable things.
 /// </summary>
 /// <param name="mention">
 /// The mention which is being considered as referential.
 /// </param>
 /// <param name="entity">
 /// The entity to which the mention is to be resolved.
 /// </param>
 /// <returns>
 /// true if the entity should be excluded, false otherwise.
 /// </returns>
 protected internal virtual bool IsExcluded(Mention.MentionContext mention, DiscourseEntity entity)
 {
     Mention.MentionContext context = entity.LastExtent;
     return mention.SentenceNumber == context.SentenceNumber && mention.IndexSpan.End <= context.IndexSpan.End;
 }
コード例 #45
0
 /// <summary>
 /// Determines if the specified entity is too far from the specified mention to be resolved to it.  
 /// Once an entity has been determined to be out of range subsequent entities are not considered.
 /// </summary>
 /// <seealso cref="IsExcluded">
 /// </seealso>
 /// <param name="mention">
 /// The mention which is being considered.
 /// </param>
 /// <param name="entity">
 /// The entity to which the mention is to be resolved.
 /// </param>
 /// <returns>
 /// true is the entity is in range of the mention, false otherwise.
 /// </returns>
 protected internal virtual bool IsOutOfRange(Mention.MentionContext mention, DiscourseEntity entity)
 {
     return false;
 }
コード例 #46
0
 private string ExcludedDeterminerMentionString(Mention.MentionContext entityContext)
 {
     System.Text.StringBuilder output = new System.Text.StringBuilder();
     bool first = true;
     Mention.IParse[] mentionTokenParses = entityContext.TokenParses;
     for (int tokenIndex = 0; tokenIndex < mentionTokenParses.Length; tokenIndex++)
     {
         Mention.IParse token = mentionTokenParses[tokenIndex];
         string tag = token.SyntacticType;
         if (tag != "DT")
         {
             if (!first)
             {
                 output.Append(" ");
             }
             output.Append(token.ToString());
             first = false;
         }
     }
     return output.ToString();
 }
コード例 #47
0
 /// <summary>
 /// Returns the text of the head word for the specified mention.
 /// </summary>
 /// <param name="mention">
 /// The mention.
 /// </param>
 /// <returns>
 /// The text of the head word for the specified mention.
 /// </returns>
 protected internal virtual string GetHeadString(Mention.MentionContext mention)
 {
     return mention.HeadTokenText.ToLower();
 }
コード例 #48
0
 private string ExcludedTheMentionString(Mention.MentionContext entityContext)
 {
     System.Text.StringBuilder output = new System.Text.StringBuilder();
     bool first = true;
     object[] mentionTokens = entityContext.Tokens;
     for (int tokenIndex = 0; tokenIndex < mentionTokens.Length; tokenIndex++)
     {
         string token = mentionTokens[tokenIndex].ToString();
         if (token != "the" && token != "The" && token != "THE")
         {
             if (!first)
             {
                 output.Append(" ");
             }
             output.Append(token);
             first = false;
         }
     }
     return output.ToString();
 }
コード例 #49
0
 private string ExcludedHonorificMentionString(Mention.MentionContext entityContext)
 {
     System.Text.StringBuilder output = new System.Text.StringBuilder();
     bool first = true;
     object[] mentionTokens = entityContext.Tokens;
     for (int tokenIndex = 0; tokenIndex < mentionTokens.Length; tokenIndex++)
     {
         string token = mentionTokens[tokenIndex].ToString();
         if (!(Linker.HonorificsPattern.Match(token).Value == token))
         {
             if (!first)
             {
                 output.Append(" ");
             }
             output.Append(token);
             first = false;
         }
     }
     return output.ToString();
 }
コード例 #50
0
 public virtual DiscourseEntity Retain(Mention.MentionContext mention, DiscourseModel discourseModel)
 {
     int entityIndex = 0;
     if (mention.Id == - 1)
     {
         return null;
     }
     for (; entityIndex < discourseModel.EntityCount; entityIndex++)
     {
         DiscourseEntity currentDiscourseEntity = discourseModel.GetEntity(entityIndex);
         Mention.MentionContext candidateExtentContext = currentDiscourseEntity.LastExtent;
         if (candidateExtentContext.Id == mention.Id)
         {
             Distances.Add(entityIndex);
             return currentDiscourseEntity;
         }
     }
     //System.err.println("AbstractResolver.Retain: non-referring entity with id: "+ec.toText()+" id="+ec.id);
     return null;
 }
コード例 #51
0
 public abstract DiscourseEntity Resolve(Mention.MentionContext expression, DiscourseModel discourseModel);
コード例 #52
0
 public abstract bool CanResolve(Mention.MentionContext mention);
コード例 #53
0
 /// <summary>
 /// Returns features indicating whether the specified mention and the specified entity are compatible.
 /// </summary>
 /// <param name="mention">
 /// The mention.
 /// </param>
 /// <param name="entity">
 /// The entity.
 /// </param>
 /// <returns> 
 /// list of features indicating whether the specified mention and the specified entity are compatible.
 /// </returns>
 private List<string> GetCompatibilityFeatures(Mention.MentionContext mention, DiscourseEntity entity)
 {
     List<string> compatibilityFeatures = new List<string>();
     string semanticCompatibilityFeature = GetSemanticCompatibilityFeature(mention, entity);
     compatibilityFeatures.Add(semanticCompatibilityFeature);
     string genderCompatibilityFeature = GetGenderCompatibilityFeature(mention, entity);
     compatibilityFeatures.Add(genderCompatibilityFeature);
     string numberCompatibilityFeature = GetNumberCompatibilityFeature(mention, entity);
     compatibilityFeatures.Add(numberCompatibilityFeature);
     if (semanticCompatibilityFeature == mSimilarityCompatible && genderCompatibilityFeature == mGenderCompatible && numberCompatibilityFeature == mNumberCompatible)
     {
         compatibilityFeatures.Add("all.compatible");
     }
     else if (semanticCompatibilityFeature == mSimilarityIncompatible || genderCompatibilityFeature == mGenderIncompatible || numberCompatibilityFeature == mNumberIncompatible)
     {
         compatibilityFeatures.Add("some.incompatible");
     }
     return compatibilityFeatures;
 }
コード例 #54
0
 private string GetExactMatchFeature(Mention.MentionContext entityContext, Mention.MentionContext compareContext)
 {
     //System.err.println("getExactMatchFeature: ec="+mentionString(ec)+" mc="+mentionString(xec));
     if (MentionString(entityContext).Equals(MentionString(compareContext)))
     {
         return "exactMatch";
     }
     else if (ExcludedHonorificMentionString(entityContext).Equals(ExcludedHonorificMentionString(compareContext)))
     {
         return "exactMatchNoHonor";
     }
     else if (ExcludedTheMentionString(entityContext).Equals(ExcludedTheMentionString(compareContext)))
     {
         return "exactMatchNoThe";
     }
     else if (ExcludedDeterminerMentionString(entityContext).Equals(ExcludedDeterminerMentionString(compareContext)))
     {
         return "exactMatchNoDT";
     }
     return null;
 }
コード例 #55
0
 /// <summary>
 /// Returns the head parse for the specified mention.
 /// </summary>
 /// <param name="mention">
 /// The mention.
 /// </param>
 /// <returns>
 /// the head parse for the specified mention.
 /// </returns>
 protected internal virtual Mention.IParse GetHead(Mention.MentionContext mention)
 {
     return mention.HeadTokenParse;
 }
コード例 #56
0
 /// <summary>
 /// Returns the index for the head word for the specified mention.
 /// </summary>
 /// <param name="mention">
 /// The mention.
 /// </param>
 /// <returns>
 /// the index for the head word for the specified mention.
 /// </returns>
 protected internal virtual int GetHeadIndex(Mention.MentionContext mention)
 {
     Mention.IParse[] mentionTokens = mention.TokenParses;
     for (int currentToken = mentionTokens.Length - 1; currentToken >= 0; currentToken--)
     {
         Mention.IParse token = mentionTokens[currentToken];
         if (token.SyntacticType != "POS" && token.SyntacticType != "," && token.SyntacticType != ".")
         {
             return currentToken;
         }
     }
     return mentionTokens.Length - 1;
 }
コード例 #57
0
        /// <summary>
        /// Returns string-match features for the the specified mention and entity.</summary>
        /// <param name="mention">
        /// The mention.
        /// </param>
        /// <param name="entity">
        /// The entity.
        /// </param>
        /// <returns>
        /// list of string-match features for the the specified mention and entity.
        /// </returns>
        protected internal virtual List<string> GetStringMatchFeatures(Mention.MentionContext mention, DiscourseEntity entity)
        {
            bool sameHead = false;
            bool modifersMatch = false;
            bool titleMatch = false;
            bool noTheModifiersMatch = false;
            List<string> features = new List<string>();
            Mention.IParse[] mentionTokens = mention.TokenParses;
            OpenNLP.Tools.Util.Set<string> entityContextModifierSet = ConstructModifierSet(mentionTokens, mention.HeadTokenIndex);
            string mentionHeadString = mention.HeadTokenText.ToLower();
            Util.Set<string> featureSet = new Util.HashSet<string>();

            foreach (Mention.MentionContext entityMention in entity.Mentions)
            {
                string exactMatchFeature = GetExactMatchFeature(entityMention, mention);
                if (exactMatchFeature != null)
                {
                    featureSet.Add(exactMatchFeature);
                }
                else if (entityMention.Parse.IsCoordinatedNounPhrase && !mention.Parse.IsCoordinatedNounPhrase)
                {
                    featureSet.Add("cmix");
                }
                else
                {
                    string mentionStrip = StripNounPhrase(mention);
                    string entityMentionStrip = StripNounPhrase(entityMention);
                    if (mentionStrip != null && entityMentionStrip != null)
                    {
                        if (IsSubstring(mentionStrip, entityMentionStrip))
                        {
                            featureSet.Add("substring");
                        }
                    }
                }
                Mention.IParse[] entityMentionTokens = entityMention.TokenParses;
                int headIndex = entityMention.HeadTokenIndex;
                //if (!mention.getHeadTokenTag().equals(entityMention.getHeadTokenTag())) {
                //  //System.err.println("skipping "+mention.headTokenText+" with "+xec.headTokenText+" because "+mention.headTokenTag+" != "+xec.headTokenTag);
                //  continue;
                //}  want to match NN NNP
                string entityMentionHeadString = entityMention.HeadTokenText.ToLower();
                // model lexical similarity
                if (mentionHeadString == entityMentionHeadString)
                {
                    sameHead = true;
                    featureSet.Add("hds=" + mentionHeadString);
                    if (!modifersMatch || !noTheModifiersMatch)
                    {
                        //only check if we haven't already found one which is the same
                        modifersMatch = true;
                        noTheModifiersMatch = true;
                        Util.Set<string> entityMentionModifierSet = ConstructModifierSet(entityMentionTokens, headIndex);
                        foreach (string modifierWord in entityContextModifierSet)
                        {
                            if (!entityMentionModifierSet.Contains(modifierWord))
                            {
                                modifersMatch = false;
                                if (modifierWord != "the")
                                {
                                    noTheModifiersMatch = false;
                                    featureSet.Add("mmw=" + modifierWord);
                                }
                            }
                        }
                    }
                }
                Util.Set<string> descriptorModifierSet = ConstructModifierSet(entityMentionTokens, entityMention.NonDescriptorStart);
                if (descriptorModifierSet.Contains(mentionHeadString))
                {
                    titleMatch = true;
                }
            }
            if (!(featureSet.Count == 0))
            {
                features.AddRange(featureSet);
            }
            if (sameHead)
            {
                features.Add("sameHead");
                if (modifersMatch)
                {
                    features.Add("modsMatch");
                }
                else if (noTheModifiersMatch)
                {
                    features.Add("nonTheModsMatch");
                }
                else
                {
                    features.Add("modsMisMatch");
                }
            }
            if (titleMatch)
            {
                features.Add("titleMatch");
            }
            return features;
        }
コード例 #58
0
 private Util.Set<string> ConstructModifierSet(Mention.IParse[] tokens, int headIndex)
 {
     Util.Set<string> modifierSet = new Util.HashSet<string>();
     for (int tokenIndex = 0; tokenIndex < headIndex; tokenIndex++)
     {
         Mention.IParse token = tokens[tokenIndex];
         modifierSet.Add(token.ToString().ToLower());
     }
     return modifierSet;
 }
コード例 #59
0
 /// <summary>
 /// Returns features indicating whether the specified mention is compatible with the pronouns
 /// of the specified entity.
 /// </summary>
 /// <param name="mention">
 /// The mention.
 /// </param>
 /// <param name="entity">
 /// The entity.
 /// </param>
 /// <returns> 
 /// list of features indicating whether the specified mention is compatible with the pronouns
 /// of the specified entity.
 /// </returns>
 protected internal virtual List<string> GetPronounMatchFeatures(Mention.MentionContext mention, DiscourseEntity entity)
 {
     bool foundCompatiblePronoun = false;
     bool foundIncompatiblePronoun = false;
     if (mention.HeadTokenTag.StartsWith("PRP"))
     {
         Dictionary<string, string> pronounMap = GetPronounFeatureMap(mention.HeadTokenText);
         //System.err.println("getPronounMatchFeatures.pronounMap:"+pronounMap);
         foreach (Mention.MentionContext candidateMention in entity.Mentions)
         {
             if (candidateMention.HeadTokenTag.StartsWith("PRP"))
             {
                 if (mention.HeadTokenText.ToUpper() == candidateMention.HeadTokenText.ToUpper())
                 {
                     foundCompatiblePronoun = true;
                     break;
                 }
                 else
                 {
                     Dictionary<string, string> candidatePronounMap = GetPronounFeatureMap(candidateMention.HeadTokenText);
                     //System.err.println("getPronounMatchFeatures.candidatePronounMap:"+candidatePronounMap);
                     bool allKeysMatch = true;
                     foreach (string key in pronounMap.Keys)
                    {
                         if (candidatePronounMap.ContainsKey(key))
                         {
                             if (pronounMap[key] != candidatePronounMap[key])
                             {
                                 foundIncompatiblePronoun = true;
                                 allKeysMatch = false;
                             }
                         }
                         else
                         {
                             allKeysMatch = false;
                         }
                     }
                     if (allKeysMatch)
                     {
                         foundCompatiblePronoun = true;
                     }
                 }
             }
         }
     }
     List<string> pronounFeatures = new List<string>();
     if (foundCompatiblePronoun)
     {
         pronounFeatures.Add("compatiblePronoun");
     }
     if (foundIncompatiblePronoun)
     {
         pronounFeatures.Add("incompatiblePronoun");
     }
     return pronounFeatures;
 }
コード例 #60
0
 protected internal override bool IsExcluded(Mention.MentionContext entityContext, DiscourseEntity discourseEntity)
 {
     if (base.IsExcluded(entityContext, discourseEntity))
     {
         return true;
     }
     return false;
     /*
     else {
     if (GEN_INCOMPATIBLE == getGenderCompatibilityFeature(ec,de)) {
     return true;
     }
     else if (NUM_INCOMPATIBLE == getNumberCompatibilityFeature(ec,de)) {
     return true;
     }
     else if (SIM_INCOMPATIBLE == getSemanticCompatibilityFeature(ec,de)) {
     return true;
     }
     return false;
     }
     */
 }