コード例 #1
0
ファイル: KernelResults.cs プロジェクト: chargen/if3-csharp
        public void matchFound(Scanner s, TreeNode match_item)
        {
            // add the match item to our matches list
            this.matches.AddLast(match_item);

            TreeFlag f = match_item.getFlags();

            this.totalBadness  += f.getBadness();
            this.totalGoodness += f.getGoodness();
            this.totalPostbad  += f.getPostbadness();

            // if the match is marked bad, add the category to our bad category list
            if (f.getBadness() > 0)
            {
                this.badCategories.AddLast(f.getCategory());
            }

            // if the match is marked good, add the category to our good category list
            if (f.getGoodness() > 0)
            {
                this.goodCategories.AddLast(f.getCategory());
            }

            // if the match is marked postbad, add the category to our postbad category list
            if (f.getPostbadness() > 0)
            {
                this.postbadCategories.AddLast(f.getCategory());
            }
        }
コード例 #2
0
ファイル: Tree.cs プロジェクト: chargen/if3-csharp
 /**
  * Add a word with the specified flags to the Tree.
  *
  * @param word
  *            string word to add
  * @param flags
  *            int flags to associate with word
  */
 public void add(String word, TreeFlag flags)
 {
     if (word.Length > 0)
     {
         int      pos = 0;
         TreeNode cur = top[(int)word[pos] & 0x7f];
         cur.add(word.Substring(pos + 1), flags, comparator, ignorer);
     }
 }
コード例 #3
0
        public void Load(TextReader reader, String prefix, TreeFlag flag)

        {
            if (reader != null)

            {
                loader.Load(reader, pattern_expander, prefix, flag);
            }
        }
コード例 #4
0
 private void addToTarget(String s, PatternExpanderTarget target, TreeFlag flag)
 {
     // no, do we have a section after us?
     if (next != null)
     {
         // yes, give the next section this request
         next.expandAllToTarget(s, target, flag);
     }
     else
     {
         // no, tell the target to add this string.
         target.add(s, flag);
     }
 }
コード例 #5
0
        public override void add(String prefix, String pattern, TreeFlag flags)
        {
            String real_pattern = prefix + pattern;

            if (real_pattern.StartsWith("http://www."))
            {
                real_pattern = real_pattern.Substring(11);
            }
            else if (real_pattern.StartsWith("http://"))
            {
                real_pattern = real_pattern.Substring(7);
            }
            // Note: We leave all other prefixes as is. We want to know about other
            // subdomains besides www and we want to
            // explicitly allows specialization of searches with https:// prefix.

            getTarget().add(real_pattern, flags);
        }
コード例 #6
0
        /**
         * <summary> The Add() method adds the string to the current node, creating
         * children nodes as needed. The specified word_flags is attached to the
         * final node. Any characters that the Ignorer says are to be ignored are
         * skipped. Any comparisons are done with the Comparator. The final Node of
         * the word is returned.
         *
         * @param word
         *            Word to add
         * @param word_flags
         *            flags to associate with word
         * @param comp
         *            Comparator to use
         * @param ig
         *            Ignorer to use
         * @return Node in the Tree of last character in the word
         */
        public TreeNode add(String word, TreeFlag word_flags, Comparator comp,
                            Ignorer ig)

        {
            TreeNode cur = this;

            for (int p = 0; p < word.Length; ++p)

            {
                char c = word[p];
                if (!ig.isIgnored(c))

                {
                    cur = cur.addChild(c, comp);
                }
            }
            cur.flags = word_flags;
            return(cur);
        }
コード例 #7
0
 public void expandAllToTarget(String prefix, PatternExpanderTarget target,
                               TreeFlag flag)
 {
     // do we have any strings to contribute to the phrase?
     if (strings.Count > 0)
     {
         // yes, iterate through them
         LinkedList <String> .Enumerator s_it = strings.GetEnumerator();
         while (s_it.MoveNext())
         {
             // get the string but prefix it with prefix
             String v = prefix + s_it.Current;
             // add the resultant string to the target
             addToTarget(v, target, flag);
         }
     }
     else
     {
         addToTarget(prefix, target, flag);
     }
 }
コード例 #8
0
 /**
  * Load a file into a scanner, make each entry have the specified flag
  *
  * @param scanner
  * @param fname
  * @param flag
  */
 private void loadScanner(Scanner scanner, String fname, TreeFlag flag)
 {
     if (file_manager != null)
     {
         try
         {
             TextReader br = file_manager.openFileNamed(fname);
             if (br != null)
             {
                 scanner.Load(
                     br,
                     "",
                     flag);
             }
         } catch (FileNotFoundException e)
         {
             log.Error(0, "File not found for :{0}", fname);
         } catch (IOException e)
         {
             log.Error(0, "IO Exception for :{0}:{1}", fname, e);
         }
     }
 }
コード例 #9
0
        public override void add(String prefix, String pattern, TreeFlag flags)
        {
            sections.clear();

            String s = prefix + pattern;

            if (s.Length > 0)
            {
                if (s[0] == '[')
                {
                    addSections(s);

                    // now iterate through all combinations of the section list
                    // and call target().add() with them.

                    iterateAllCombinations(flags);
                }
                else
                {
                    // no optional sections here, just add the string
                    getTarget().add(s, flags);
                }
            }
        }
コード例 #10
0
 private void iterateAllCombinations(TreeFlag flags)
 {
     sections.expandAllToTarget("", getTarget(), flags);
 }
コード例 #11
0
ファイル: PatternExpander.cs プロジェクト: chargen/if3-csharp
 public void add(String pattern, TreeFlag flags)
 {
     add("", pattern, flags);
 }
コード例 #12
0
        /**
         *
         * Set the flags for this Node
         *
         * @param f
         *            TreeFlag flags
         */
        public void setFlags(TreeFlag f)

        {
            flags = f;
        }
コード例 #13
0
        public int quantifyResultsForUrl(String url, KernelResults hostname_results,
                                         KernelResults url_results)
        {
            int  result     = 0;
            bool is_good    = false;
            bool is_bad     = false;
            bool is_unknown = true;

            // if the hostname is known bad then we are bad
            if (hostname_results.getTotalBadness() > 0)
            {
                is_bad     = true;
                is_good    = false;
                is_unknown = false;
            }

            // if the hostname is known good then we are good
            if (hostname_results.getTotalGoodness() > 0)
            {
                is_good    = true;
                is_bad     = false;
                is_unknown = false;
            }

            // if the hostname or the full url is known postbad then we are bad
            if (hostname_results.getTotalPostbad() > 0 || url_results.getTotalPostbad() > 0)
            {
                is_bad     = true;
                is_good    = false;
                is_unknown = false;
            }

            // if the site is not yet known then check the rest of the url
            if (is_unknown)
            {
                // if the rest of the url is known bad then we are bad
                if (url_results.getTotalBadness() > 0)
                {
                    is_bad     = true;
                    is_good    = false;
                    is_unknown = false;
                }

                // if the rest of the url is known postbad then we are bad
                if (url_results.getTotalPostbad() > 0)
                {
                    is_bad     = true;
                    is_good    = false;
                    is_unknown = false;
                }

                if (url_results.getTotalGoodness() > 0)
                {
                    foreach (TreeNode i in url_results.getMatches())
                    {
                        TreeFlag f = i.getFlags();

                        if (f.getGoodness() > 0)

                        {
                            String extracted = i.extractWord();

                            if (url == extracted ||
                                url == "http://" + extracted ||
                                url == "http://www." + extracted)
                            {
                                is_bad     = false;
                                is_good    = true;
                                is_unknown = false;
                                break;
                            }
                        }
                    }
                }
            }

            if (is_bad)
            {
                result = -1;
            }
            if (is_good)
            {
                result = 1;
            }

            return(result);
        }
コード例 #14
0
 public override void add(String prefix, String pattern, TreeFlag flags)
 {
     getTarget().add(prefix + pattern, flags);
 }
コード例 #15
0
        public void Load(System.IO.TextReader reader, PatternExpander pattern_expander, String prefix, TreeFlag flag)

        {
            String line;

            while ((line = reader.ReadLine()) != null)

            {
                if (line.Length > 4)

                {
                    pattern_expander.add(prefix, line, flag);
                }
            }
        }
コード例 #16
0
ファイル: PatternExpander.cs プロジェクト: chargen/if3-csharp
 public abstract void add(String prefix, String pattern, TreeFlag flags);
コード例 #17
0
 public override void add(String prefix, String pattern, TreeFlag flags)
 {
     base.add(common_prefix + fixUrlString(prefix), fixUrlString(pattern), flags);
 }
コード例 #18
0
 public void add(String pattern, TreeFlag flags)
 {
     System.Console.Out.WriteLine("ADD: " + flags.getFlag() + " " + pattern);
 }