コード例 #1
0
 public FragmentSenitment(String frag, Priorpolarity pri, Int32 pn = 0, Int32 ln = 0)
 {
     ParagraphNumber = pn;
     LineNumber      = ln;
     Fragment        = frag;
     Priorpolarity   = pri;
 }
コード例 #2
0
 public Record(Record record)
 {
     type          = record.type;
     len           = record.len;
     word1         = record.word1;
     pos1          = record.pos1;
     stemmed1      = record.stemmed1;
     priorpolarity = record.priorpolarity;
 }
コード例 #3
0
 public Record(String record)
 {
     InitLogicTable();
     String[] properties = record.Split(' ');
     if (IsDictFormatNormal)
     {
         foreach (String str in properties)
         {
             String[] keyValue = str.Split('=');
             if (keyValue[0].Equals("word1"))
             {
                 word1 = keyValue[1];
             }
             else if (keyValue[0].Equals("len"))
             {
                 len = Int32.Parse(keyValue[1]);
             }
             else if (keyValue[0].Equals("type"))
             {
                 type = (LevelType)logicTable[keyValue[1]];
             }
             else if (keyValue[0].Equals("pos1"))
             {
                 pos1 = (PartofSpeech)logicTable[keyValue[1]];
             }
             else if (keyValue[0].Equals("priorpolarity"))
             {
                 priorpolarity = (Priorpolarity)logicTable[keyValue[1]];
             }
             else if (keyValue[0].Equals("stemmed1"))
             {
                 if (keyValue[0].Equals("n", StringComparison.OrdinalIgnoreCase))
                 {
                     stemmed1 = false;
                 }
                 else
                 {
                     stemmed1 = true;
                 }
             }
         }
     }
     else
     {
         word1         = properties[0];
         priorpolarity = (Priorpolarity)logicTable[properties[1]];
     }
 }
コード例 #4
0
 private static String GetLabel(Priorpolarity oldPriop)
 {
     if (oldPriop == Priorpolarity.positive)
     {
         return("1");
     }
     else if (oldPriop == Priorpolarity.negative)
     {
         return("0");
     }
     else if (oldPriop == Priorpolarity.weakneg)
     {
         return("0");
     }
     return("1");
 }
コード例 #5
0
 private static Priorpolarity GetNewPriorpolarity(List <String> words, Priorpolarity oldPriop)
 {
     foreach (String word in words)
     {
         if (mNegativeWords.Contains(word))
         {
             if (oldPriop == Priorpolarity.negative)
             {
                 return(Priorpolarity.positive);
             }
             else if (oldPriop == Priorpolarity.positive)
             {
                 return(Priorpolarity.negative);
             }
             else if (oldPriop == Priorpolarity.weakneg)
             {
                 return(Priorpolarity.positive);
             }
         }
     }
     return(oldPriop);
 }
コード例 #6
0
 public void Do()
 {
     foreach (String path in mDocumentsPath)
     {
         StreamWriter sw       = null;
         StreamWriter swNumber = null;
         StreamWriter swLabel  = null;
         try
         {
             sw       = File.CreateText(path + ".extract");
             swNumber = File.CreateText(path + ".number");
             swLabel  = File.CreateText(path + ".label");
         }
         catch (Exception)
         {
             //System.Console.WriteLine(ex.ToString());
             continue;
         }
         Document doc = new Document(path);
         doc.Open();
         while (!doc.EndOfFile)
         {
             Paragraph prag               = doc.NextParagraph();
             Int32     LineNumberInPrag   = 0;
             Boolean   hasNoSentimentWord = true;
             foreach (String str in prag.Lines)
             {
                 hasNoSentimentWord = true;
                 LineNumberInPrag++;
                 List <String> words = NomalizeLineToWords(str);
                 for (int i = window; i < words.Count - window; ++i)
                 {
                     try
                     {
                         //If current word is not in the dictionary, then an exception would be thrown.
                         //And in exception handle function, we do nothing but continue to process next word.
                         Record record = DictionaryBuilder.WordDict[words[i]];
                         //for example, let the current word be the center, and give a window which length is 2
                         //then the fragment would contain 5 words
                         List <String> fragmentstr       = words.GetRange(i - window, window * 2 + 1);
                         String        fragment          = ToFragment(fragmentstr);
                         Priorpolarity fragPriorpolarity = GetNewPriorpolarity(fragmentstr, record.priorpolarity);
                         sw.WriteLine((new FragmentSenitment(fragment, fragPriorpolarity).ToString()));
                         swNumber.WriteLine(String.Format("{0} {1}", doc.CurrentParagraphNumber, LineNumberInPrag));
                         swLabel.WriteLine(GetLabel(fragPriorpolarity));
                         hasNoSentimentWord = false;
                     }
                     catch (Exception)
                     {
                         //System.Console.WriteLine (ex.ToString ());
                         continue;
                     }
                 }
                 if (LineNumberInPrag == 1 && hasNoSentimentWord && addAbstraction)
                 {
                     words.Remove("[");
                     words.Remove("]");
                     for (int i = words.Count; i < window * 2 + 1; i++)
                     {
                         words.Add("BLANK");
                     }
                     List <String> fragmentstr = words.GetRange(0, window * 2 + 1);
                     String        fragment    = ToFragment(fragmentstr);
                     sw.WriteLine((new FragmentSenitment(fragment, prag.Priorpolarity).ToString()));
                     swNumber.WriteLine(String.Format("{0} {1}", doc.CurrentParagraphNumber, LineNumberInPrag));
                     swLabel.WriteLine(GetLabel(prag.Priorpolarity));
                 }
             }
             if (prag.Length != 0)
             {
                 swNumber.WriteLine("end " + prag.Length);
             }
         }
         doc.Close();
         sw.Close();
         swNumber.Close();
         swLabel.Close();
     }
     mDocumentsPath.Clear();
 }