コード例 #1
0
        //CAUTION: The specified return values MUST correspond to the POSType database table entries
        //         otherwise every core function won't work properly
        public static short GetDBPOSTagId(DistinctChunkTags chunkTag)
        {
            switch (chunkTag)
            {
            case DistinctChunkTags.NounPhrase:
                return(1);

            case DistinctChunkTags.AdjectivePhrase:
                return(2);

            default:
                return(-1);
            }
        }
コード例 #2
0
        public List <ChunkedGroup> GetNearestGroupById(int groupId, int[] termIds, DistinctChunkTags chunkTag, int maxDistance)
        {
            List <ChunkedGroup> foundGroups  = new List <ChunkedGroup>();
            List <ChunkedGroup> targetGroups = Groups.Where(a => a.Id == groupId).ToList();

            //If a group is inserted in the database as multiple phrases because of the maxPhraseSize limit
            //in the phrase extraction phase, then the groupId in the XML structure only holds one of those
            //phrase values. To still be able to find the target group by the ineer term ids we do the following:
            if (targetGroups.Count == 0)
            {
                targetGroups = Groups.Where(a => {
                    var ids = a.Terms.Select(b => b.Id);
                    return(!termIds.Except(ids).Any());
                }).ToList();
            }

            foreach (ChunkedGroup targetGroup in targetGroups)
            {
                //Get the positions in the sentence by the first and last term of the group id
                int firstPosition = targetGroup.Terms.Count > 0 ? targetGroup.Terms.First().Order : -1;
                int lastPosition  = targetGroup.Terms.Count > 0 ? targetGroup.Terms.Last().Order : -1;

                //If we find a group of the specified chunk tag OR any group with a related POS tag of the specified chunk,
                //and the distance between the first term of our target group and the last term of a candidate group
                //or the last term of the target group and the first term of a candidate group, is smaller
                //than the specified target distance add the candidate group
                if (firstPosition >= 0 && lastPosition >= 0)
                {
                    foundGroups.AddRange(Groups.Where(a => (a.Tag == chunkTag.StringValue() ||
                                                            a.Terms.Any(b => StaticMappings.ChunkPOSMapping[chunkTag].Contains(b.POS))) &&
                                                      a.Terms.Count > 0 &&
                                                      (Math.Abs(lastPosition - a.Terms.First().Order) < maxDistance ||
                                                       Math.Abs(firstPosition - a.Terms.Last().Order) < maxDistance)));
                }
            }

            foreach (ChunkedGroup targetGroup in targetGroups)
            {
                foundGroups.Remove(targetGroup);
            }

            return(foundGroups.Distinct().ToList());
        }