當前位置: 首頁>>代碼示例>>Python>>正文


Python gen_parser_ops.document_source方法代碼示例

本文整理匯總了Python中syntaxnet.ops.gen_parser_ops.document_source方法的典型用法代碼示例。如果您正苦於以下問題:Python gen_parser_ops.document_source方法的具體用法?Python gen_parser_ops.document_source怎麽用?Python gen_parser_ops.document_source使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在syntaxnet.ops.gen_parser_ops的用法示例。


在下文中一共展示了gen_parser_ops.document_source方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: ValidateDocuments

# 需要導入模塊: from syntaxnet.ops import gen_parser_ops [as 別名]
# 或者: from syntaxnet.ops.gen_parser_ops import document_source [as 別名]
def ValidateDocuments(self):
    doc_source = gen_parser_ops.document_source(
        task_context=self.context_file, batch_size=1)
    with self.test_session() as sess:
      logging.info('Reading document1')
      doc, last = self.ReadNextDocument(sess, doc_source)
      self.assertEqual(len(doc.token), 12)
      self.assertEqual(u'लाजमी', doc.token[9].word)
      self.assertFalse(last)
      logging.info('Reading document2')
      doc, last = self.ReadNextDocument(sess, doc_source)
      self.assertEqual(len(doc.token), 13)
      self.assertEqual(u'भंग', doc.token[9].word)
      self.assertFalse(last)
      logging.info('Hitting end of the dataset')
      doc, last = self.ReadNextDocument(sess, doc_source)
      self.assertTrue(doc is None)
      self.assertTrue(last) 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:20,代碼來源:lexicon_builder_test.py

示例2: CheckUntokenizedDoc

# 需要導入模塊: from syntaxnet.ops import gen_parser_ops [as 別名]
# 或者: from syntaxnet.ops.gen_parser_ops import document_source [as 別名]
def CheckUntokenizedDoc(self, sentence, words, starts, ends):
    self.WriteContext('untokenized-text')
    logging.info('Writing text file to: %s', self.corpus_file)
    with open(self.corpus_file, 'w') as f:
      f.write(sentence)
    sentence, _ = gen_parser_ops.document_source(
        task_context=self.context_file, batch_size=1)
    with self.test_session() as sess:
      sentence_doc = self.ReadNextDocument(sess, sentence)
      self.assertEqual(len(sentence_doc.token), len(words))
      self.assertEqual(len(sentence_doc.token), len(starts))
      self.assertEqual(len(sentence_doc.token), len(ends))
      for i, token in enumerate(sentence_doc.token):
        self.assertEqual(token.word.encode('utf-8'), words[i])
        self.assertEqual(token.start, starts[i])
        self.assertEqual(token.end, ends[i]) 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:18,代碼來源:text_formats_test.py

示例3: CheckSegmentationTrainingData

# 需要導入模塊: from syntaxnet.ops import gen_parser_ops [as 別名]
# 或者: from syntaxnet.ops.gen_parser_ops import document_source [as 別名]
def CheckSegmentationTrainingData(self, doc_lines, doc_text, doc_words,
                                    break_levels):
    # Prepare context.
    self.WriteContext('segment-train-data')

    # Prepare test sentence.
    with open(self.corpus_file, 'w') as f:
      f.write(''.join(doc_lines))

    # Test converted sentence.
    sentence, _ = gen_parser_ops.document_source(
        task_context=self.context_file, batch_size=1)
    with self.test_session() as sess:
      sentence_doc = self.ReadNextDocument(sess, sentence)
      self.assertEqual(doc_text.decode('utf-8'), sentence_doc.text)
      self.assertEqual([t.decode('utf-8') for t in doc_words],
                       [t.word for t in sentence_doc.token])
      self.assertEqual(break_levels,
                       [t.break_level for t in sentence_doc.token]) 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:21,代碼來源:text_formats_test.py

示例4: main

# 需要導入模塊: from syntaxnet.ops import gen_parser_ops [as 別名]
# 或者: from syntaxnet.ops.gen_parser_ops import document_source [as 別名]
def main(unused_argv):
  logging.set_verbosity(logging.INFO)
  with tf.Session() as sess:
    src = gen_parser_ops.document_source(batch_size=32,
                                         corpus_name=FLAGS.corpus_name,
                                         task_context=FLAGS.task_context)
    sentence = sentence_pb2.Sentence()
    while True:
      documents, finished = sess.run(src)
      logging.info('Read %d documents', len(documents))
      for d in documents:
        sentence.ParseFromString(d)
        tr = asciitree.LeftAligned()
        d = to_dict(sentence)
        print 'Input: %s' % sentence.text
        print 'Parse:'
        tr_str = tr(d)
        pat = re.compile(r'\s*@\d+$')
        for tr_ln in tr_str.splitlines():
          print pat.sub('', tr_ln)

      if finished:
        break 
開發者ID:ringringyi,項目名稱:DOTA_models,代碼行數:25,代碼來源:conll2tree.py

示例5: main

# 需要導入模塊: from syntaxnet.ops import gen_parser_ops [as 別名]
# 或者: from syntaxnet.ops.gen_parser_ops import document_source [as 別名]
def main(unused_argv):
  logging.set_verbosity(logging.INFO)
  with tf.Session() as sess:
    src = gen_parser_ops.document_source(batch_size=32,
                                         corpus_name=FLAGS.corpus_name,
                                         task_context=FLAGS.task_context)
    sentence = sentence_pb2.Sentence()
    while True:
      documents, finished = sess.run(src)
      logging.info('Read %d documents', len(documents))
      for d in documents:
        sentence.ParseFromString(d)
        tr = asciitree.LeftAligned()
        d = to_dict(sentence)
        print('Input: %s' % sentence.text)
        print('Parse:')
        tr_str = tr(d)
        pat = re.compile(r'\s*@\d+$')
        for tr_ln in tr_str.splitlines():
          print(pat.sub('', tr_ln))

      if finished:
        break 
開發者ID:itsamitgoel,項目名稱:Gun-Detector,代碼行數:25,代碼來源:conll2tree.py

示例6: ValidateDocuments

# 需要導入模塊: from syntaxnet.ops import gen_parser_ops [as 別名]
# 或者: from syntaxnet.ops.gen_parser_ops import document_source [as 別名]
def ValidateDocuments(self):
    doc_source = gen_parser_ops.document_source(self.context_file, batch_size=1)
    with self.test_session() as sess:
      logging.info('Reading document1')
      doc, last = self.ReadNextDocument(sess, doc_source)
      self.assertEqual(len(doc.token), 12)
      self.assertEqual(u'लाजमी', doc.token[9].word)
      self.assertFalse(last)
      logging.info('Reading document2')
      doc, last = self.ReadNextDocument(sess, doc_source)
      self.assertEqual(len(doc.token), 13)
      self.assertEqual(u'भंग', doc.token[9].word)
      self.assertFalse(last)
      logging.info('Hitting end of the dataset')
      doc, last = self.ReadNextDocument(sess, doc_source)
      self.assertTrue(doc is None)
      self.assertTrue(last) 
開發者ID:coderSkyChen,項目名稱:Action_Recognition_Zoo,代碼行數:19,代碼來源:lexicon_builder_test.py

示例7: CheckUntokenizedDoc

# 需要導入模塊: from syntaxnet.ops import gen_parser_ops [as 別名]
# 或者: from syntaxnet.ops.gen_parser_ops import document_source [as 別名]
def CheckUntokenizedDoc(self, sentence, words, starts, ends):
    self.WriteContext('untokenized-text')
    logging.info('Writing text file to: %s', self.corpus_file)
    with open(self.corpus_file, 'w') as f:
      f.write(sentence)
    sentence, _ = gen_parser_ops.document_source(
        self.context_file, batch_size=1)
    with self.test_session() as sess:
      sentence_doc = self.ReadNextDocument(sess, sentence)
      self.assertEqual(len(sentence_doc.token), len(words))
      self.assertEqual(len(sentence_doc.token), len(starts))
      self.assertEqual(len(sentence_doc.token), len(ends))
      for i, token in enumerate(sentence_doc.token):
        self.assertEqual(token.word.encode('utf-8'), words[i])
        self.assertEqual(token.start, starts[i])
        self.assertEqual(token.end, ends[i]) 
開發者ID:coderSkyChen,項目名稱:Action_Recognition_Zoo,代碼行數:18,代碼來源:text_formats_test.py

示例8: CheckSegmentationTrainingData

# 需要導入模塊: from syntaxnet.ops import gen_parser_ops [as 別名]
# 或者: from syntaxnet.ops.gen_parser_ops import document_source [as 別名]
def CheckSegmentationTrainingData(self, doc_lines, doc_text, doc_words,
                                    break_levels):
    # Prepare context.
    self.WriteContext('segment-train-data')

    # Prepare test sentence.
    with open(self.corpus_file, 'w') as f:
      f.write(''.join(doc_lines))

    # Test converted sentence.
    sentence, _ = gen_parser_ops.document_source(
        self.context_file, batch_size=1)
    with self.test_session() as sess:
      sentence_doc = self.ReadNextDocument(sess, sentence)
      self.assertEqual(doc_text.decode('utf-8'), sentence_doc.text)
      self.assertEqual([t.decode('utf-8') for t in doc_words],
                       [t.word for t in sentence_doc.token])
      self.assertEqual(break_levels,
                       [t.break_level for t in sentence_doc.token]) 
開發者ID:coderSkyChen,項目名稱:Action_Recognition_Zoo,代碼行數:21,代碼來源:text_formats_test.py


注:本文中的syntaxnet.ops.gen_parser_ops.document_source方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。