예제 #1
0
        public CollectionModel GetGridFormDataSource([FromUri] string dataObjectUID,
                                                     [FromUri] string activityUID)
        {
            try {
                var dataObject = StepDataObject.Parse(dataObjectUID);

                var activity = ProjectItem.Parse(activityUID);

                FixedList <Posting> list = PostingList.GetPostings(dataObject.DataItem,
                                                                   activity,
                                                                   dataObject.DataItem.DataType);

                var data = list.Select(x => {
                    var json = x.ExtensionData.ToDictionary();

                    json.Add("uid", x.UID);

                    if (dataObject.DataItem.Terms == "Actividades.CNH.CustomGrid")
                    {
                        json = Reporting.SubtaskCNH.LoadFields(dataObject, json, activity);
                    }

                    return(json);
                });

                return(new CollectionModel(this.Request, data.ToArray()));
            } catch (Exception e) {
                throw base.CreateHttpException(e);
            }
        }
예제 #2
0
        internal override void  CreatePostings(RawPostingList[] postings, int start, int count)
        {
            int end = start + count;

            for (int i = start; i < end; i++)
            {
                postings[i] = new PostingList();
            }
        }
예제 #3
0
        private void SaveIndices(IList <Token> tokens, IList <string> linkTexts, UrlFile urlFile, ulong oldUrlFileId)
        {
            var invertedIndices = new List <Index>();
            var postingLists    = new List <PostingList>();

            foreach (var token in tokens)
            {
                var key = new IndexKey
                {
                    Word      = token.Word,
                    UrlFileId = urlFile.UrlFileId,
                };

                var weight = ScoringHelper.CalculateIndexWeight(urlFile.Title,
                                                                urlFile.TextContent,
                                                                urlFile.Url,
                                                                DateTime.FromBinary((long)urlFile.PublishDate),
                                                                token.OccurencesInTitle,
                                                                token.OccurencesInLinks,
                                                                linkTexts,
                                                                token.Word,
                                                                token.WordFrequency,
                                                                token.Positions);
                var index = new Index
                {
                    Key                 = key,
                    WordFrequency       = token.WordFrequency,
                    OccurencesInTitle   = token.OccurencesInTitle,
                    OccurencesInLinks   = token.OccurencesInLinks,
                    OccurencesInHeaders = token.OccurencesInHeaders,
                    Weight              = weight,
                };
                index.Positions.AddRange(token.Positions);

                invertedIndices.Add(index);

                var postingList = new PostingList
                {
                    Word              = token.Word,
                    WordFrequency     = token.WordFrequency,
                    DocumentFrequency = 1,
                    IsAdd             = true,
                };
                var posting = new Posting
                {
                    UrlFileId = urlFile.UrlFileId,
                    Weight    = weight,
                };
                postingList.Postings.Add(posting);

                postingLists.Add(postingList);
            }
            mConfig.PostingListStore.SavePostingLists(urlFile.UrlFileId, postingLists);
            mConfig.InvertedIndexStore.SaveIndices(urlFile.UrlFileId, invertedIndices);
        }
예제 #4
0
        public CollectionModel GetProjectItemFiles([FromUri] string projectItemUID)
        {
            try {
                var projectItem = ProjectItem.Parse(projectItemUID);

                FixedList <FormerMediaFile> list = PostingList.GetPostedItems <FormerMediaFile>(projectItem, "ProjectItem.MediaFile");

                return(new CollectionModel(this.Request, list.ToResponse(),
                                           typeof(FormerMediaFile).FullName));
            } catch (Exception e) {
                throw base.CreateHttpException(e);
            }
        }
예제 #5
0
        public CollectionModel GetAllProjectFiles()
        {
            try {
                FixedList <Posting> list = PostingList.GetPostings("ProjectItem.MediaFile");

                var projects = UserProjectSecurity.GetUserProjectFixedList();

                list = list.FindAll(x => projects.Exists(y => y.Id == x.GetNodeObjectItem <ProjectItem>().Project.Id));

                return(new CollectionModel(this.Request, list.ToProjectItemFileResponse(),
                                           typeof(FormerMediaFile).FullName));
            } catch (Exception e) {
                throw base.CreateHttpException(e);
            }
        }
예제 #6
0
        public NoDataModel RemoveProjectItemFile(string projectItemUID, string fileUID)
        {
            try {
                var projectItem = ProjectItem.Parse(projectItemUID);

                FixedList <Posting> list = PostingList.GetPostings(projectItem, "ProjectItem.MediaFile");

                var posting = list.Find(x => x.PostedItemUID == fileUID);

                Assertion.Require(posting.NodeObjectUID == projectItem.UID,
                                  $"ProjectItem {projectItem.Name} does not have the file {posting.PostedItemUID}.");

                posting.Delete();

                return(new NoDataModel(this.Request));
            } catch (Exception e) {
                throw base.CreateHttpException(e);
            }
        }
예제 #7
0
        public List <Page> PruneContenders(string userQuery)
        {
            List <Page> contenderPages = new List <Page>();

            foreach (string term in userQuery.Split(" "))
            {
                if (PostingList.ContainsKey(term))
                {
                    Console.WriteLine($"Contains term {term}");
                    foreach (int id in PostingList[term])
                    {
                        if (!contenderPages.Any(p => p.Id == id))
                        {
                            contenderPages.Add(Pages.Find(p => p.Id == id));
                        }
                    }
                }
            }
            return(contenderPages);
        }
예제 #8
0
 private void PopulatePostingList(List <Term> sortedTerms)
 {
     // We store the list of ID's containing a term key.
     for (int i = 0; i < sortedTerms.Count; i++)
     {
         if (PostingList.ContainsKey(sortedTerms[i].Word))
         {
             if (!PostingList[sortedTerms[i].Word].Contains(sortedTerms[i].Id))
             {
                 PostingList[sortedTerms[i].Word].Add(sortedTerms[i].Id);
             }
         }
         else
         {
             PostingList.Add(sortedTerms[i].Word, new List <int>()
             {
                 sortedTerms[i].Id
             });
         }
     }
 }
예제 #9
0
        public List <int> Not(PostingList secondList, List <PostingList> pstList)
        {
            secondList.Word = "NOT" + secondList.Word;
            List <int> notList = new List <int>();

            if (secondList.documentList != null)
            {
                foreach (var listItem in pstList)
                {
                    foreach (var doc in listItem.documentList)
                    {
                        foreach (var docI in secondList.documentList)
                        {
                            if (doc != docI && !(notList.IndexOf(doc) > -1))
                            {
                                notList.Add(doc);
                            }
                        }
                    }
                }
            }


            if (secondList.documentList == null)
            {
                foreach (var listItem in pstList)
                {
                    foreach (var doc in listItem.documentList)
                    {
                        if (!(notList.IndexOf(doc) > -1))
                        {
                            notList.Add(doc);
                        }
                    }
                }
            }

            notList.Sort();
            return(notList);
        }
예제 #10
0
        public void Test_GetDocumentsContainingTerm_Returns_ExpectedDocuments()
        {
            var index = new SortedDictionary <string, PostingList>()
            {
                ["red"] = new PostingList {
                    Postings = new List <long> {
                        1, 2, 3, 4, 5
                    }
                },
                ["blue"] = new PostingList {
                    Postings = new List <long> {
                        2, 3, 4, 7
                    }
                },
                ["green"] = new PostingList {
                    Postings = new List <long> {
                        6, 7
                    }
                },
            };

            var inMemoryIndex = new IndexSegment()
            {
                Index = index
            };
            var sut = new SimpleBooleanSearchEngine();

            sut.LoadIndexFromMemory(inMemoryIndex);

            var result       = sut.GetDocumentsContainingTerm("blue");
            var expectedDocs = new PostingList {
                Postings = new List <long> {
                    2, 3, 4, 7
                }
            };

            result.Postings.Count.Should().Be(4);
            result.Should().BeEquivalentTo(expectedDocs);
        }
예제 #11
0
        private Posting LoadOrCreatePosting()
        {
            const string postingType = "Steps.Autofill.FileData";

            var currentPostings = PostingList.GetPostings(this.StepDataObject,
                                                          this.Activity, postingType);

            if (currentPostings.Count == 1)
            {
                return(currentPostings[0]);
            }

            if (currentPostings.Count > 1)
            {
                throw Assertion.EnsureNoReachThisCode("Multiple file postings per activity are not yet implemented.");
            }


            var posting = new Posting(postingType, this.StepDataObject, this.Activity);

            posting.Save();

            return(posting);
        }
		internal override void  CreatePostings(RawPostingList[] postings, int start, int count)
		{
			int end = start + count;
			for (int i = start; i < end; i++)
				postings[i] = new PostingList();
		}
예제 #13
0
 public string DisplayForCache()
 {
     return(PostingList.DisplayForCache());
 }
예제 #14
0
        public List <PostingList> CreatPostingList(String[] indexedDoc, String[] vocab, String qryType, String qryStr)
        {
            List <Vocab>       vb           = CreatVocab(vocab);
            List <PostingList> psList       = new List <PostingList>();
            List <PostingList> retnPSList   = new List <PostingList>();
            List <String>      stringsInQry = qryStr.Split(' ').ToList();

            stringsInQry = CleanUpQry(stringsInQry);

            char[] delimiters = new char[] { ',', '[', ']' };

            for (int i = 0; i < indexedDoc.Length; i++)
            {
                String[] wordsListPerLine = indexedDoc[i].Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
                foreach (string str in wordsListPerLine)
                {
                    if (psList.Count == 0)
                    {
                        PostingList ps = new PostingList();
                        ps.PositioninVocab = Int32.Parse(str);
                        ps.Word            = vb.Where(x => x.position == Int32.Parse(str)).Select(x => x.word).First();
                        ps.documentList    = new List <int>();
                        ps.documentList.Add(i + 1);
                        psList.Add(ps);
                    }
                    else
                    {
                        var found = psList.Where(x => x.PositioninVocab == Int32.Parse(str)).ToList();
                        if (found.Count() == 0)
                        {
                            PostingList ps = new PostingList();
                            ps.PositioninVocab = Int32.Parse(str);
                            ps.Word            = vb.Where(x => x.position == Int32.Parse(str)).Select(x => x.word).First();
                            ps.documentList    = new List <int>();
                            ps.documentList.Add(i + 1);
                            psList.Add(ps);
                        }
                        else
                        {
                            var baseqry = found.FirstOrDefault().documentList;
                            if (baseqry.Where(x => x == i + 1).ToList().Count() == 0)
                            {
                                baseqry.Add(i + 1);
                            }
                        }
                    }
                }
            }

            if (qryType.ToUpper().Equals("AND_NOT"))
            {
                return(psList);
            }

            int wordIndex = 0;

            foreach (String qry in stringsInQry)
            {
                wordIndex++;
                foreach (var c in psList)
                {
                    if (c.Word.TrimStart().TrimEnd().Equals(qry.TrimStart().TrimEnd()))
                    {
                        c.wordIndex = wordIndex;
                        retnPSList.Add(c);
                    }
                }
            }

            return(retnPSList);
        }