Method: Ariel::ExampleDocumentLoader.load_labeled_example
- Defined in:
- lib/ariel/example_document_loader.rb
.load_labeled_example(file, structure, loaded_example_hash) ⇒ Object
Assumes it is passed a root parent
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ariel/example_document_loader.rb', line 9 def self.load_labeled_example(file, structure, loaded_example_hash) raise ArgumentError, "Passed structure is not root parent" if structure.parent string = file.respond_to?(:read) ? file.read : file tokenstream = TokenStream.new tokenstream.tokenize(string, true) root = ExtractedNode.new(:root, tokenstream, structure) structure.apply_extraction_tree_on(root, true) root.each_descendant(true) do |extracted_node| if extracted_node.parent loaded_example_hash[extracted_node..structure] << extracted_node end extracted_node.tokenstream. end return loaded_example_hash end |