alchemy-concept-extractor 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/alchemy-concept-extractor.rb +72 -0
  3. metadata +142 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 69f2c86990c3effefcc3824cb20a9a103e55d023
4
+ data.tar.gz: a6703d0c41bf75220ed400cd29e4d90b11e39485
5
+ SHA512:
6
+ metadata.gz: 72c6b270eb46c580dc38e6f3ca33e8856c5fbabd20e1528c40845dfdf4c10cad2abe164c8bb318beeafb610623c5d1421ea44d477d89b297178db13bfeb0ab86
7
+ data.tar.gz: 68abbd8612bbe9bd2e5cac02abb2edf98ca0176960a920ca6573c081980cdab8683088f98acb00e65626240fadb902c256765be302cc13a68ad00d535849e463
@@ -0,0 +1,72 @@
1
+ module AlchemyConceptExtractor
2
+ require 'uri'
3
+ require 'readline'
4
+ require 'rest_client'
5
+ require 'json'
6
+ require 'pp'
7
+ require 'rdf'
8
+
9
+ include RDF
10
+
11
+ require_relative 'models/extractor.rb'
12
+ require_relative 'models/reporter.rb'
13
+ require_relative 'models/refiner.rb'
14
+
15
+ class ConceptExtractor
16
+ attr :api_key
17
+ attr :outfile_location
18
+ attr :datfile_location
19
+ attr :output_format
20
+ attr :rest_client
21
+ attr :refiner
22
+
23
+ def initialize(api_key,
24
+ outfile_location,
25
+ datfile_location = "uris.dat",
26
+ output_format = :ntriples,
27
+ rest_client = RestClient)
28
+
29
+ @api_key = api_key
30
+ @outfile_location = outfile_location
31
+ @datfile_location = datfile_location
32
+ @output_format = output_format
33
+ @rest_client = rest_client
34
+ @refiner = Refiner.new
35
+ end
36
+
37
+ def uris
38
+ uris_file = IO.read(@datfile_location)
39
+ uris = uris_file.split("\n")
40
+
41
+ uris
42
+ end
43
+
44
+ def append_graph_to_file(graph)
45
+ reporter = Reporter.new(graph)
46
+ serialised_rdf = reporter.report(@output_format)
47
+
48
+ File.open outfile_location, 'a' do |file|
49
+ file.puts serialised_rdf
50
+ end
51
+ end
52
+
53
+ def extract
54
+ extractor = Extractor.new(@api_key,@rest_client)
55
+
56
+ File.delete @outfile_location if File.exist? @outfile_location
57
+ uris.each do | uri |
58
+ puts "Disambiguating: #{uri}"
59
+
60
+ concepts = extractor.get_concepts uri
61
+ graph = @refiner.refine(concepts)
62
+ append_graph_to_file(graph)
63
+ end
64
+ end
65
+ end
66
+
67
+ def self.extract(api_key,datfile_location,outfile_location,output_format = :ntriples, rest_client = RestClient)
68
+ concept_extractor = ConceptExtractor.new(api_key,outfile_location,datfile_location,output_format,rest_client)
69
+ concept_extractor.extract
70
+ end
71
+
72
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alchemy-concept-extractor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Philip Lamond
8
+ - Robert Kenny
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: 1.6.7
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - '>='
26
+ - !ruby/object:Gem::Version
27
+ version: 1.6.7
28
+ - !ruby/object:Gem::Dependency
29
+ name: json
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: 1.7.5
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: 1.7.5
42
+ - !ruby/object:Gem::Dependency
43
+ name: rdf
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: 0.3.8
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: 0.3.8
56
+ - !ruby/object:Gem::Dependency
57
+ name: rdf-rdfxml
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: 0.3.8
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 0.3.8
70
+ - !ruby/object:Gem::Dependency
71
+ name: rdf-trig
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: 0.1.3
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: 0.1.3
84
+ - !ruby/object:Gem::Dependency
85
+ name: rdf-turtle
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: 0.1.2
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: 0.1.2
98
+ - !ruby/object:Gem::Dependency
99
+ name: rdf-xsd
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: 0.3.8
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: 0.3.8
112
+ description: Extracts concepts for a given URI from the Alchemy API (http://www.alchemyapi.com/)
113
+ email: philip.lamond@bbc.co.uk
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - lib/alchemy-concept-extractor.rb
119
+ homepage: https://github.com/BBC-Knowlearn/alchemy-concept-extractor.git
120
+ licenses: []
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.0.3
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Alchemy API Concept Extractor
142
+ test_files: []