Class: AlchemyConceptExtractor::ConceptExtractor
- Inherits:
-
Object
- Object
- AlchemyConceptExtractor::ConceptExtractor
- Defined in:
- lib/alchemy-concept-extractor.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#datfile_location ⇒ Object
readonly
Returns the value of attribute datfile_location.
-
#outfile_location ⇒ Object
readonly
Returns the value of attribute outfile_location.
-
#output_format ⇒ Object
readonly
Returns the value of attribute output_format.
-
#refiner ⇒ Object
readonly
Returns the value of attribute refiner.
-
#rest_client ⇒ Object
readonly
Returns the value of attribute rest_client.
Instance Method Summary collapse
- #append_graph_to_file(graph) ⇒ Object
- #extract ⇒ Object
-
#initialize(api_key, outfile_location, datfile_location = "uris.dat", output_format = :ntriples, rest_client = RestClient) ⇒ ConceptExtractor
constructor
A new instance of ConceptExtractor.
- #uris ⇒ Object
Constructor Details
#initialize(api_key, outfile_location, datfile_location = "uris.dat", output_format = :ntriples, rest_client = RestClient) ⇒ ConceptExtractor
Returns a new instance of ConceptExtractor.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/alchemy-concept-extractor.rb', line 23 def initialize(api_key, outfile_location, datfile_location = "uris.dat", output_format = :ntriples, rest_client = RestClient) @api_key = api_key @outfile_location = outfile_location @datfile_location = datfile_location @output_format = output_format @rest_client = rest_client @refiner = Refiner.new end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
16 17 18 |
# File 'lib/alchemy-concept-extractor.rb', line 16 def api_key @api_key end |
#datfile_location ⇒ Object (readonly)
Returns the value of attribute datfile_location.
18 19 20 |
# File 'lib/alchemy-concept-extractor.rb', line 18 def datfile_location @datfile_location end |
#outfile_location ⇒ Object (readonly)
Returns the value of attribute outfile_location.
17 18 19 |
# File 'lib/alchemy-concept-extractor.rb', line 17 def outfile_location @outfile_location end |
#output_format ⇒ Object (readonly)
Returns the value of attribute output_format.
19 20 21 |
# File 'lib/alchemy-concept-extractor.rb', line 19 def output_format @output_format end |
#refiner ⇒ Object (readonly)
Returns the value of attribute refiner.
21 22 23 |
# File 'lib/alchemy-concept-extractor.rb', line 21 def refiner @refiner end |
#rest_client ⇒ Object (readonly)
Returns the value of attribute rest_client.
20 21 22 |
# File 'lib/alchemy-concept-extractor.rb', line 20 def rest_client @rest_client end |
Instance Method Details
#append_graph_to_file(graph) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/alchemy-concept-extractor.rb', line 44 def append_graph_to_file(graph) reporter = Reporter.new(graph) serialised_rdf = reporter.report(@output_format) File.open outfile_location, 'a' do |file| file.puts serialised_rdf end end |
#extract ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/alchemy-concept-extractor.rb', line 53 def extract extractor = Extractor.new(@api_key,@rest_client) File.delete @outfile_location if File.exist? @outfile_location uris.each do | uri | puts "Disambiguating: #{uri}" concepts = extractor.get_concepts uri graph = @refiner.refine(concepts) append_graph_to_file(graph) end end |
#uris ⇒ Object
37 38 39 40 41 42 |
# File 'lib/alchemy-concept-extractor.rb', line 37 def uris uris_file = IO.read(@datfile_location) uris = uris_file.split("\n") uris end |