コード例 #1
0
 public int Build(TextReader textReader,
                  ProcessSentCallbackDelegate processSentCallback,
                  int sentNumberCallbackStep,
                  ProcessXmlErrorSentCallbackDelegate processXmlErrorSentCallback,
                  StartBuildCallbackDelegate startBuildCallback)
 {
     throw (new NotImplementedException("learner. not used"));
 }
コード例 #2
0
        /*
         * public int Build( TextReader                          textReader,
         *                ProcessSentCallbackDelegate         processSentCallback,
         *                int                                 sentNumberCallbackStep,
         *                ProcessXmlErrorSentCallbackDelegate processXmlErrorSentCallback,
         *                StartBuildCallbackDelegate          startBuildCallback )
         * {
         *  var sentNumber = 1;
         *  for ( var line = textReader.ReadLine(); line != null; line = textReader.ReadLine() )
         *  {
         *      var xe = ToXElement( line, sentNumber );
         *      if ( xe != null )
         *      {
         *          var words = from n in xe.Nodes()
         *                      from word in CreateWords( n )
         *                      select word;
         *
         *          _Words.Clear();
         *          _Words.AddRange( words );
         *
         *          _NerCRFSuiteModelBuilderAdapter.AppendWords( _Words );
         *      }
         *      else
         *      {
         *          processXmlErrorSentCallback( line, sentNumber );
         *      }
         *
         *
         *      if ( (sentNumber % sentNumberCallbackStep) == 0 )
         *      {
         *          processSentCallback( sentNumber );
         *      }
         *      sentNumber++;
         *  }
         *  if ( (sentNumber % sentNumberCallbackStep) != 0 )
         *  {
         *      processSentCallback( sentNumber );
         *  }
         *
         *  startBuildCallback();
         *
         *  _NerCRFSuiteModelBuilderAdapter.Build();
         *
         *  return (sentNumber);
         * }
         */
        #endregion

        public int CreateCrfInputFormatFile(TextWriter textWriter,
                                            TextReader textReader,
                                            ProcessSentCallbackDelegate processSentCallback,
                                            int sentNumberCallbackStep,
                                            ProcessXmlErrorSentCallbackDelegate processXmlErrorSentCallback)
        {
            var sentNumber = 1;

            for (var line = textReader.ReadLine(); line != null; line = textReader.ReadLine())
            {
                var xe = ToXElement(line, sentNumber);
                if (xe != null)
                {
                    var words = from n in xe.Nodes()
                                from word in CreateWords(n)
                                select word;

                    _Words.Clear();
                    _Words.AddRange(words);

                    if (0 < _Words.Count)
                    {
                        _NerScriber.WriteCrfAttributesWords4ModelBuilder(textWriter, _Words);
                    }
                }
                else
                {
                    processXmlErrorSentCallback(line, sentNumber);
                }

                if ((sentNumber % sentNumberCallbackStep) == 0)
                {
                    processSentCallback(sentNumber);
                }
                sentNumber++;
            }
            if ((sentNumber % sentNumberCallbackStep) != 0)
            {
                processSentCallback(sentNumber);
            }

            return(sentNumber);
        }