Class: Ariel::LabeledDocumentLoader
- Inherits:
-
Object
- Object
- Ariel::LabeledDocumentLoader
- Defined in:
- lib/ariel/labeled_document_loader.rb
Overview
Provides methods that read an example document, using a Node::Structure tree to populate a tree of Nodes with each labeled example.
Class Method Summary collapse
-
.supervise_learning(structure, *labeled_strings) ⇒ Object
As its first argument it takes a root Node::Structure to which any learnt rules will be added.
Class Method Details
.supervise_learning(structure, *labeled_strings) ⇒ Object
As its first argument it takes a root Node::Structure to which any learnt rules will be added. The following arguments are strings containing labeled examples for members of the passed Node::Structure tree. Ariel#learn is the preferred interface for rule-learning - this one may change.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ariel/labeled_document_loader.rb', line 14 def supervise_learning(structure, *labeled_strings) raise ArgumentError, "No labeled strings were given" if labeled_strings.size==0 loaded_example_hash=process_labeled_strings(structure, *labeled_strings) loaded_example_hash.each_pair do |structure_node, example_nodes| if structure_node.node_type==:list_item exhaustive=true else exhaustive=false end examples = collect_labeled_tokenstreams(example_nodes, :start) Log.info "Learning #{"exhaustive " if exhaustive}rules for node #{structure_node.node_name} with #{example_nodes.size} examples" learner = Learner.new(*examples) start_rules = learner.learn_rule :forward, exhaustive Log.info "Learnt start rules #{start_rules.inspect}" examples = collect_labeled_tokenstreams(example_nodes, :end) learner = Learner.new(*examples) end_rules = learner.learn_rule :back, exhaustive Log.info "Learnt end rules, #{end_rules.inspect}" structure_node.ruleset=RuleSet.new(start_rules, end_rules) end return structure end |