Class: AlchemyConceptExtractor::ConceptExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/alchemy-concept-extractor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_keyObject (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_locationObject (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_locationObject (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_formatObject (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

#refinerObject (readonly)

Returns the value of attribute refiner.



21
22
23
# File 'lib/alchemy-concept-extractor.rb', line 21

def refiner
  @refiner
end

#rest_clientObject (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

#extractObject



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

#urisObject



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