コード例 #1
0
 private void onContentUpdate(NewsPair p)
 {
     if (p == CurrentNewsPair)
     {
         OnNewsContentUpdate?.Invoke();
     }
 }
コード例 #2
0
 public void LoadPreviousNewsPair()
 {
     if (currentNewsPairIndex > 0 && currentNewsPairIndex < currentActivePairs.Count())
     {
         CurrentNewsPair = currentActivePairs.ElementAt(--currentNewsPairIndex);
     }
     OnPreviousNewsPair?.Invoke(currentNewsPairIndex > 0);
 }
コード例 #3
0
 private string getOutputString(NewsPair pair)
 {
     string[] tmp = new string[pair.OriginalContent.Length];
     for (int i = 0; i < tmp.Length; i++)
     {
         tmp[i] = pair.OriginalContent[i];
     }
     tmp[config.RelationLabelIndex] = pair.RelationLabel;
     return(string.Join(config.SeparatorWrite, tmp));
 }
コード例 #4
0
 private void writeNewsPairToFile()
 {
     if (currentActivePairs.Count() == backLimit)
     {
         NewsPair val = currentActivePairs.ElementAt(0);
         handler.WriteToOutputFile(val);
         currentNewsPairIndex--;
         currentActivePairs.RemoveAt(0);
     }
 }
コード例 #5
0
        private void WriteToUncertainOutputFile(NewsPair pair)
        {
            if (uncertainOutputFileWriter == null)
            {
                uncertainOutputFileWriter = new StreamWriter(new FileStream(labelWork.UncertainOutputFileName, FileMode.Append, FileAccess.Write), Encoding.UTF8);
            }
            string val = getUncertainOutputString(pair);

            uncertainOutputFileWriter.WriteLine(val);
            uncertainOutputFileWriter.Flush();
        }
コード例 #6
0
        public void WriteToOutputFile(NewsPair pair)
        {
            string val = getOutputString(pair);

            outputFileWriter.WriteLine(val);
            outputFileWriter.Flush();
            if (pair.LabelUncertain)
            {
                WriteToUncertainOutputFile(pair);
            }
        }
コード例 #7
0
 private string getUncertainOutputString(NewsPair pair)
 {
     string[] tmp = new string[pair.OriginalContent.Length + 1];
     for (int i = 0; i < pair.OriginalContent.Length; i++)
     {
         tmp[i] = pair.OriginalContent[i];
     }
     tmp[config.RelationLabelIndex]   = pair.RelationLabel;
     tmp[pair.OriginalContent.Length] = pair.LineNum.ToString();
     return(string.Join(config.SeparatorWrite, tmp));
 }
コード例 #8
0
        private bool addNextNewsPairToList()
        {
            NewsPair next = handler.ParseNextLine();

            if (next == null)
            {
                return(true);
            }
            currentActivePairs.Add(next);
            return(false);
        }
コード例 #9
0
 private void startContentReadWorker(NewsPair pair)
 {
     if (pair == null)
     {
         return;
     }
     contentReadWorker = new BackgroundWorker();
     contentReadWorker.WorkerReportsProgress      = false;
     contentReadWorker.WorkerSupportsCancellation = true;
     contentReadWorker.DoWork             += worker_DoWork;
     contentReadWorker.RunWorkerCompleted += worker_RunWorkerCompleted;
     contentReadWorker.RunWorkerAsync(pair);
 }
コード例 #10
0
        public void InitActiveNewsPairList()
        {
            int i = 0;

            while (i++ < backLimit && !addNextNewsPairToList())
            {
                ;
            }
            if (currentActivePairs.Count() > 0)
            {
                CurrentNewsPair = currentActivePairs.ElementAt(currentNewsPairIndex);
                OnNextNewsPair?.Invoke(currentNewsPairIndex > 0);
            }
            else
            {
                OnEndOfFileReached?.Invoke(currentActivePairs.Count() > 0);
            }
        }
コード例 #11
0
        public void DestroyNewsFileHandler()
        {
            if (handler == null)
            {
                return;
            }
            int end = isAtEOF ? currentActivePairs.Count() : Math.Min(currentActivePairs.Count() - 1, currentNewsPairIndex);

            for (int i = 0; i < end; i++)
            {
                handler.WriteToOutputFile(currentActivePairs.ElementAt(i));
            }
            handler.Destroy();
            currentActivePairs.Clear();
            currentNewsPairIndex = 0;
            handler         = null;
            CurrentNewsPair = null;
            OnNewsFileHandlerDestroy?.Invoke();
        }
コード例 #12
0
 public void LoadNextNewsPair()
 {
     isAtEOF = false;
     if (currentNewsPairIndex >= currentActivePairs.Count() - 1)
     {
         writeNewsPairToFile();
         isAtEOF = addNextNewsPairToList();
     }
     if (!isAtEOF)
     {
         currentNewsPairIndex++;
         CurrentNewsPair = currentActivePairs.ElementAt(currentNewsPairIndex);
         OnNextNewsPair?.Invoke(currentNewsPairIndex > 0);
     }
     else
     {
         OnEndOfFileReached?.Invoke(currentActivePairs.Count() > 0);
     }
 }
コード例 #13
0
        public NewsPair ParseNextLine()
        {
            string line = inputFileReader.ReadLine();

            if (line == null)
            {
                return(null);
            }
            CurrentLineNum++;
            string[] split = line.Split(config.SeparatorRead, StringSplitOptions.None);
            NewsPair rv    = null;

            try
            {
                if (split.Length >= config.NumElementFullSourceFile)
                {
                    rv = new NewsPair(CurrentLineNum, split, split[config.News1TitleIndex],
                                      split[config.News1ContentIndex],
                                      split[config.News2TitleIndex],
                                      split[config.News2ContentIndex],
                                      (int)double.Parse(split[config.CommonTitleWordsIndex])
                                      );
                }
                else if (split.Length >= config.NumElementSimplifiedSourceFile)
                {
                    rv = new NewsPair(CurrentLineNum, split, split[config.News1TitleIndex],
                                      LOADING,
                                      split[config.News2TitleIndex],
                                      LOADING,
                                      (int)double.Parse(split[config.CommonTitleWordsIndex])
                                      );
                    contentReadQ.Enqueue(rv);
                    notifyContentReadWorker();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.StackTrace);
            }
            return(rv);
        }
コード例 #14
0
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
            NewsPair         pair   = e.Argument as NewsPair;

            if ((worker.CancellationPending == true))
            {
                e.Cancel = true;
                return;
            }
            string[] rv = new string[config.NumElementNewsContentFile];
            for (int i = 0; i < rv.Length; i++)
            {
                rv[i] = "(无内容)";
            }
            lock (sharedWorkerResourceLock)
            {
                if (newsFileReader == null)
                {
                    setNewsContentForPair(pair, rv);
                    return;
                }
                string line = newsFileReader.ReadLine();
                if (line == null)
                {
                    setNewsContentForPair(pair, rv);
                    return;
                }
                CurrentContentFileLineNum++;
                string[] split = line.Split(config.SeparatorRead, StringSplitOptions.None);
                if (split.Length != config.NumElementNewsContentFile)
                {
                    setNewsContentForPair(pair, rv);
                    return;
                }
                setNewsContentForPair(pair, split);
            }
            e.Result = pair;
        }
コード例 #15
0
 private void setNewsContentForPair(NewsPair pair, string[] contentArray)
 {
     pair.News1Content = contentArray[config.News1ContentIndexInContentFile];
     pair.News2Content = contentArray[config.News2ContentIndexInContentFile];
 }