Пример #1
0
        /* Function: ResolveNewImageFiles
         *
         * Goes through the IDs of newly created image files and sees if they serve as better targets for any existing links.
         *
         * Parameters:
         *
         *		imageFileIDs - The set of IDs to check.  Every file represented here must have the same lowercase file name.
         *		lcFileName - The all lowercase file name shared by all of the file IDs.  It does not include any part of the path.
         *		accessor - The <Accessor> used for the database.
         *
         * Requirements:
         *
         *		- Requires the accessor to have at least a read/possible write lock.  If the link changes it will be upgraded to
         *		  read/write automatically.
         *
         */
        protected void ResolveNewImageFiles(NumberSet imageFileIDs, string lcFileName, Accessor accessor)
        {
            List <ImageLink> imageLinks = accessor.GetImageLinksByFileName(lcFileName, Delegates.NeverCancel,
                                                                           Accessor.GetImageLinkFlags.DontLookupClasses);


            // Go through each image link and see if any of the new image files serve as a better target.

            foreach (var imageLink in imageLinks)
            {
                int bestMatchFileID = imageLink.TargetFileID;
                int bestMatchScore  = imageLink.TargetScore;

                foreach (int imageFileID in imageFileIDs)
                {
                    int newScore = Manager.Score(imageLink, EngineInstance.Files.FromID(imageFileID), bestMatchScore);

                    if (newScore > bestMatchScore)
                    {
                        bestMatchFileID = imageFileID;
                        bestMatchScore  = newScore;
                    }
                }

                if (imageLink.TargetFileID != bestMatchFileID)
                {
                    int oldTargetFileID = imageLink.TargetFileID;

                    imageLink.TargetFileID = bestMatchFileID;
                    imageLink.TargetScore  = bestMatchScore;

                    accessor.UpdateImageLinkTarget(imageLink, oldTargetFileID);
                }
            }
        }
Пример #2
0
        /* Function: ResolveLink
         *
         * Calculates a new target for the passed link ID.
         *
         * Requirements:
         *
         *		- Requires the accessor to have at least a read/possible write lock.  If the link target changes it will be upgraded to
         *		  read/write automatically.
         *
         */
        protected void ResolveLink(int linkID, Accessor accessor)
        {
            Link link = accessor.GetLinkByID(linkID, Accessor.GetLinkFlags.DontLookupClasses);
            List <EndingSymbol> endingSymbols = accessor.GetAlternateLinkEndingSymbols(linkID);

            if (endingSymbols == null)
            {
                endingSymbols = new List <EndingSymbol>();
            }

            endingSymbols.Add(link.EndingSymbol);

            // We only need the body's length, not its contents.
            List <Topic> topics = accessor.GetTopicsByEndingSymbol(endingSymbols, Delegates.NeverCancel,
                                                                   Accessor.GetTopicFlags.BodyLengthOnly |
                                                                   Accessor.GetTopicFlags.DontLookupClasses |
                                                                   Accessor.GetTopicFlags.DontLookupContexts);

            List <LinkInterpretation> alternateInterpretations = null;

            if (link.Type == LinkType.NaturalDocs)
            {
                string ignore;
                alternateInterpretations = EngineInstance.Comments.NaturalDocsParser.LinkInterpretations(link.Text,
                                                                                                         Comments.Parsers.NaturalDocs.LinkInterpretationFlags.FromOriginalText |
                                                                                                         Comments.Parsers.NaturalDocs.LinkInterpretationFlags.AllowNamedLinks |
                                                                                                         Comments.Parsers.NaturalDocs.LinkInterpretationFlags.AllowPluralsAndPossessives,
                                                                                                         out ignore);
            }

            int  bestMatchTopicID = 0;
            int  bestMatchClassID = 0;
            long bestMatchScore   = 0;

            foreach (Topic topic in topics)
            {
                long score = Manager.Score(link, topic, bestMatchScore, alternateInterpretations);

                if (score > bestMatchScore)
                {
                    bestMatchTopicID = topic.TopicID;
                    bestMatchClassID = topic.ClassID;
                    bestMatchScore   = score;
                }
            }

            if (bestMatchTopicID != link.TargetTopicID ||
                bestMatchClassID != link.TargetClassID ||
                bestMatchScore != link.TargetScore)
            {
                int oldTargetTopicID = link.TargetTopicID;
                int oldTargetClassID = link.TargetClassID;

                link.TargetTopicID = bestMatchTopicID;
                link.TargetClassID = bestMatchClassID;
                link.TargetScore   = bestMatchScore;

                accessor.UpdateLinkTarget(link, oldTargetTopicID, oldTargetClassID);
            }
        }
Пример #3
0
        /* Function: ResolveNewTopics
         *
         * Goes through the IDs of newly created <Topics> and sees if they serve as better targets for any existing links.
         *
         * Parameters:
         *
         *		topicIDs - The set of IDs to check.  Every <Topic> represented here must have the same <EndingSymbol>.
         *		endingSymbol - The <EndingSymbol> shared by all of the topic IDs.
         *		accessor - The <Accessor> used for the database.
         *
         * Requirements:
         *
         *		- Requires the accessor to have at least a read/possible write lock.  If the link changes it will be upgraded to
         *		  read/write automatically.
         *
         */
        protected void ResolveNewTopics(NumberSet topicIDs, EndingSymbol endingSymbol, Accessor accessor)
        {
            // We only need the body's length, not its contents.
            List <Topic> topics = accessor.GetTopicsByID(topicIDs, Delegates.NeverCancel,
                                                         Accessor.GetTopicFlags.BodyLengthOnly |
                                                         Accessor.GetTopicFlags.DontLookupClasses |
                                                         Accessor.GetTopicFlags.DontLookupContexts);
            List <Link> links = accessor.GetLinksByEndingSymbol(endingSymbol, Delegates.NeverCancel,
                                                                Accessor.GetLinkFlags.DontLookupClasses);

            // Go through each link and see if any of the topics serve as a better target.  It's better for the links to be the outer loop
            // because we can generate alternate interpretations only once per link.

            foreach (Link link in links)
            {
                List <LinkInterpretation> alternateInterpretations = null;

                if (link.Type == LinkType.NaturalDocs)
                {
                    string ignore;
                    alternateInterpretations = EngineInstance.Comments.NaturalDocsParser.LinkInterpretations(link.Text,
                                                                                                             Comments.Parsers.NaturalDocs.LinkInterpretationFlags.FromOriginalText |
                                                                                                             Comments.Parsers.NaturalDocs.LinkInterpretationFlags.AllowNamedLinks |
                                                                                                             Comments.Parsers.NaturalDocs.LinkInterpretationFlags.AllowPluralsAndPossessives,
                                                                                                             out ignore);
                }

                int  bestMatchTopicID = link.TargetTopicID;
                int  bestMatchClassID = link.TargetClassID;
                long bestMatchScore   = link.TargetScore;

                foreach (Topic topic in topics)
                {
                    // No use rescoring the existing target.
                    if (topic.TopicID != link.TargetTopicID)
                    {
                        long score = Manager.Score(link, topic, bestMatchScore, alternateInterpretations);

                        if (score > bestMatchScore)
                        {
                            bestMatchTopicID = topic.TopicID;
                            bestMatchClassID = topic.ClassID;
                            bestMatchScore   = score;
                        }
                    }
                }

                if (bestMatchTopicID != link.TargetTopicID ||
                    bestMatchClassID != link.TargetClassID ||
                    bestMatchScore != link.TargetScore)
                {
                    int oldTargetTopicID = link.TargetTopicID;
                    int oldTargetClassID = link.TargetClassID;

                    link.TargetTopicID = bestMatchTopicID;
                    link.TargetClassID = bestMatchClassID;
                    link.TargetScore   = bestMatchScore;

                    accessor.UpdateLinkTarget(link, oldTargetTopicID, oldTargetClassID);
                }
            }
        }
Пример #4
0
        /* Function: ResolveImageLink
         *
         * Calculates a new target for the passed image link ID.
         *
         * Requirements:
         *
         *		- Requires the accessor to have at least a read/possible write lock.  If the link target changes it will be upgraded to
         *		  read/write automatically.
         *
         */
        protected void ResolveImageLink(int imageLinkID, Accessor accessor)
        {
            ImageLink imageLink = accessor.GetImageLinkByID(imageLinkID, Accessor.GetImageLinkFlags.DontLookupClasses);

            int bestMatchFileID = 0;
            int bestMatchScore  = 0;


            // First try the path relative to the source file.

            Path pathRelativeToSourceFile = EngineInstance.Files.FromID(imageLink.FileID).FileName.ParentFolder + '/' + imageLink.Path;
            File fileRelativeToSourceFile = EngineInstance.Files.FromPath(pathRelativeToSourceFile);

            if (fileRelativeToSourceFile != null && fileRelativeToSourceFile.Deleted == false)
            {
                int score = Manager.Score(imageLink, fileRelativeToSourceFile, bestMatchScore);

                if (score > bestMatchScore)
                {
                    bestMatchScore  = score;
                    bestMatchFileID = fileRelativeToSourceFile.ID;
                }
            }


            // Next try the path relative to any image folders.

            foreach (var fileSource in EngineInstance.Files.FileSources)
            {
                if (fileSource.Type == InputType.Image)
                {
                    Path pathRelativeToFileSource = fileSource.MakeAbsolute(imageLink.Path);
                    File fileRelativeToFileSource = EngineInstance.Files.FromPath(pathRelativeToFileSource);

                    if (fileRelativeToFileSource != null && fileRelativeToFileSource.Deleted == false)
                    {
                        int score = Manager.Score(imageLink, fileRelativeToFileSource, bestMatchScore);

                        if (score > bestMatchScore)
                        {
                            bestMatchScore  = score;
                            bestMatchFileID = fileRelativeToFileSource.ID;
                        }
                    }
                }
            }


            // Update the database

            if (bestMatchFileID != imageLink.TargetFileID ||
                bestMatchScore != imageLink.TargetScore)
            {
                int oldTargetFileID = imageLink.TargetFileID;

                imageLink.TargetFileID = bestMatchFileID;
                imageLink.TargetScore  = bestMatchScore;

                accessor.UpdateImageLinkTarget(imageLink, oldTargetFileID);
            }
        }