Exemple #1
0
        private static void AddOrOverwriteWordCountFeature(ZoneTree tree)
        {
            var leafWalker = new BreadthFirstWalkerFactory().CreateLeafWalker();

            tree.Accept(new FeatureExtractionVisitor <Zone>(TOKENS_FEATURE_NAME, new Tokens(_naturalLanguageProcessor)), leafWalker);
            tree.Accept(new FeatureExtractionVisitor <Zone>(WORD_COUNT_FEATURE_NAME, new WordCount(TOKENS_FEATURE_NAME)), leafWalker);
        }
Exemple #2
0
        /// <summary>
        /// Executes the algorithm on the tree strcuture
        /// </summary>
        /// <param name="tree">The tree structure</param>
        protected override void ExecuteImplementation(ZoneTree zoneTree)
        {
            var leafWalker = new BreadthFirstWalkerFactory().CreateLeafWalker();

            zoneTree.Accept(new FeatureExtractionVisitor <Zone>(ZoneFeature.ArticleContent_SentenceCount, new SentenceCount(_naturalLanguageProcessor)), leafWalker);
            zoneTree.Accept(new TreeNodeClassifier(_paragraphLabel, new FeatureGreaterThanOrEqual <TreeNode>(ZoneFeature.ArticleContent_SentenceCount, SENTENCE_THRESHOLD)), leafWalker);
        }
        /// <summary>
        /// Executes the algorithm on the tree strcuture
        /// </summary>
        /// <param name="tree">The tree structure</param>
        protected override void ExecuteImplementation(ColumnTree columnTree)
        {
            // Zone tree
            var zoneTree = columnTree.ZoneTree;

            var paragraphClassifier = new ParagraphLabeler(_naturalLanguageProcessor, _paragraphLabel);

            paragraphClassifier.Execute(zoneTree);

            var leafWalker = new BreadthFirstWalkerFactory().CreateLeafWalker();

            zoneTree.Accept(new FeatureExtractionVisitor <Zone>(_tokenFeatureName, new Tokens(_naturalLanguageProcessor)), leafWalker);
            zoneTree.Accept(new FeatureExtractionVisitor <Zone>(ZoneFeature.ArticleContent_WordCount, new WordCount(_tokenFeatureName)), leafWalker);
            zoneTree.Accept(new FeatureExtractionVisitor <Zone>(ZoneFeature.ArticleContent_Score, new ArticleContentScore(_paragraphLabel, ZoneFeature.ArticleContent_WordCount)), leafWalker);
            zoneTree.Accept(new FeatureExtractionVisitor <Zone>(ZoneFeature.ArticleContent_AggregateScore, new ArticleContentScoreAggregator(ZoneFeature.ArticleContent_Score, ZoneFeature.ArticleContent_AggregateScore)), new BreadthFirstWalkerFactory().CreateReversed());

            int totalScore = zoneTree.Root.GetFeature(ZoneFeature.ArticleContent_AggregateScore).AsInt();

            if (totalScore > 0)
            {
                zoneTree.Accept(new FeatureExtractionVisitor <TreeNode>(ZoneFeature.ArticleContent_ScoreFraction, new ArticleContentScoreFraction(totalScore, ZoneFeature.ArticleContent_AggregateScore)));

                // Column tree
                columnTree.Accept(new FeatureExtractionVisitor <Column>(ColumnFeature.ArticleContent_ScoreFraction, new ColumnArticleContentScoreFraction(ZoneFeature.ArticleContent_ScoreFraction)));
                columnTree.Accept(new FeatureExtractionVisitor <TreeNode>(ColumnFeature.ArticleContent_DeltaScoreFraction, new DeltaArticleContentScoreFraction(ColumnFeature.ArticleContent_ScoreFraction)));
                columnTree.Accept(new TreeNodeClassifier(_articleContentLabel, new FeatureGreaterThanOrEqual <Column>(ColumnFeature.ArticleContent_DeltaScoreFraction, DELTA_THRESHOLD)), new ArticleContentScoreFractionWalker(ColumnFeature.ArticleContent_ScoreFraction));
            }
            else
            {
                columnTree.Root.AddClassification(_articleContentLabel);
            }

            columnTree.Accept(new TreeNodeClassifier(_articleContentLabel, new DescendantFilter(_articleContentLabel, _articleContentLabel)));
            zoneTree.Accept(new TreeNodeClassifier(_articleContentLabel, new DescendantFilter(_articleContentLabel, _articleContentLabel)));
        }