rdfobjects-pho 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rdf_objects/pho/index_set.rb +117 -0
- data/lib/rdf_objects/pho/store.rb +35 -0
- data/lib/rdf_objects/pho.rb +2 -0
- metadata +5 -4
@@ -0,0 +1,117 @@
|
|
1
|
+
module RDFObject
|
2
|
+
class Index
|
3
|
+
attr_reader :name, :property, :analyzer, :weight
|
4
|
+
def initialize(args={})
|
5
|
+
unless args.empty?
|
6
|
+
["name","property","analyzer","weight"].each do |prop|
|
7
|
+
if args[prop] || args[prop.to_s]
|
8
|
+
self.send("set_prop".to_sym, (args[prop] || args[prop.to_s]))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def set_name(name)
|
15
|
+
@name = name
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_property(property)
|
19
|
+
if property.is_a?(RDFObject::Resource)
|
20
|
+
@property = property
|
21
|
+
else
|
22
|
+
@property = RDFObject::Resource.new(property)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_analyzer(analyzer)
|
27
|
+
if analyzer.is_a?(RDFObject::Resource)
|
28
|
+
@analyzer = analyzer
|
29
|
+
else
|
30
|
+
unless analyzer =~ /^http:\/\//
|
31
|
+
analyzer = "http://schemas.talis.com/2007/bigfoot/analyzers#analyzer"
|
32
|
+
end
|
33
|
+
@analyzer = RDFObject::Resource.new(analyzer)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def set_weight(boost)
|
38
|
+
unless boost.nil?
|
39
|
+
@weight = boost.to_f
|
40
|
+
else
|
41
|
+
@weight = nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
class IndexSet
|
48
|
+
def initialize(store_name=nil)
|
49
|
+
@fields = {}
|
50
|
+
@store = nil
|
51
|
+
end
|
52
|
+
|
53
|
+
def <<(index)
|
54
|
+
@fields[index.name] = index
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def get_index(name)
|
59
|
+
return @fields[name]
|
60
|
+
end
|
61
|
+
|
62
|
+
def set_store(store_name)
|
63
|
+
@store = store_name
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def to_fpmap
|
68
|
+
raise unless @store
|
69
|
+
fpmap = RDFObject::Resource.new("#{@store}/config/fpmaps/1")
|
70
|
+
fpmap.relate("[rdf:type]","http://schemas.talis.com/2006/bigfoot/configuration#FieldPredicateMap")
|
71
|
+
@fields.values.each do |index|
|
72
|
+
field = RDFObject::Resource.new("#{fpmap.uri}##{index.name}")
|
73
|
+
field.relate("http://schemas.talis.com/2006/frame/schema#property", index.property)
|
74
|
+
field.assert("http://schemas.talis.com/2006/frame/schema#name", index.name)
|
75
|
+
if index.analyzer
|
76
|
+
field.relate("http://schemas.talis.com/2006/bigfoot/configuration#analyzer", index.analyzer)
|
77
|
+
end
|
78
|
+
fpmap.relate("http://schemas.talis.com/2006/frame/schema#mappedDatatypeProperty", field)
|
79
|
+
end
|
80
|
+
fpmap
|
81
|
+
end
|
82
|
+
|
83
|
+
def to_qp
|
84
|
+
raise unless @store
|
85
|
+
qp = RDFObject::Resource.new("#{@store}/config/queryprofiles/1")
|
86
|
+
qp.relate("[rdf:type]", "http://schemas.talis.com/2006/bigfoot/configuration#QueryProfile")
|
87
|
+
@fields.values.each do |index|
|
88
|
+
next unless index.weight
|
89
|
+
weight = RDFObject::Resource.new("#{qp.uri}##{index.name}")
|
90
|
+
weight.assert("http://schemas.talis.com/2006/bigfoot/configuration#weight", index.weight.to_s)
|
91
|
+
weight.assert("http://schemas.talis.com/2006/frame/schema#name", index.name)
|
92
|
+
end
|
93
|
+
qp
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.new_from_response(fpmap, qp)
|
97
|
+
index_set = self.new(rdfo.uri.sub("/config/fpmaps/1",""))
|
98
|
+
[*fpmap["http://schemas.talis.com/2006/frame/schema#mappedDatatypeProperty"]].each do |field|
|
99
|
+
next unless field
|
100
|
+
index = RDFObject::Index.new
|
101
|
+
index.set_name(field["http://schemas.talis.com/2006/frame/schema#name"].to_s)
|
102
|
+
index.set_property(field["http://schemas.talis.com/2006/frame/schema#property"].resource)
|
103
|
+
if field["http://schemas.talis.com/2006/bigfoot/configuration#analyzer"]
|
104
|
+
index.set_analyzer(field["http://schemas.talis.com/2006/bigfoot/configuration#analyzer"].resource)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
[*qp["http://schemas.talis.com/2006/bigfoot/configuration#fieldWeight"]].each do |weight|
|
109
|
+
next unless weight
|
110
|
+
name = weight["http://schemas.talis.com/2006/frame/schema#name"].to_s
|
111
|
+
index = index_set.get_index(name)
|
112
|
+
index.set_weight(weight["http://schemas.talis.com/2006/bigfoot/configuration#weight"])
|
113
|
+
end
|
114
|
+
return index_set
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -44,6 +44,17 @@ module RDFObject
|
|
44
44
|
response.resource = response.collection[u]
|
45
45
|
return response
|
46
46
|
end
|
47
|
+
|
48
|
+
def get_indexes
|
49
|
+
fp_map_resp = get_field_predicate_map
|
50
|
+
qp_resp = get_query_profile
|
51
|
+
RDFObject::IndexSet.new_from_response(fp_map_resp.resource, qp_resp.resource)
|
52
|
+
end
|
53
|
+
|
54
|
+
def set_indexes(index_set)
|
55
|
+
index_set.set_store(@storeuri)
|
56
|
+
put_field_predicate_map(index_set.to_fpmap)
|
57
|
+
end
|
47
58
|
|
48
59
|
def get_job(uri)
|
49
60
|
response = super(uri)
|
@@ -58,10 +69,34 @@ module RDFObject
|
|
58
69
|
end
|
59
70
|
|
60
71
|
def get_query_profile(output=::Pho::ACCEPT_JSON)
|
72
|
+
u = build_uri("/config/queryprofiles/1")
|
61
73
|
response = super(output)
|
62
74
|
response.extend ::RDFObject::StoreResponse
|
75
|
+
response.resource = response.collection[u]
|
63
76
|
response
|
64
77
|
end
|
78
|
+
|
79
|
+
def put_field_predicate_map(fpmap)
|
80
|
+
if fpmap.is_a?(RDFObject::Resource)
|
81
|
+
rdf = fpmap.to_rdf_object.to_xml(4)
|
82
|
+
elsif fpmap.is_a?(String)
|
83
|
+
rdf = fpmap
|
84
|
+
end
|
85
|
+
u = build_uri("/config/fpmaps/1")
|
86
|
+
headers = {"Content-Type" => "application/rdf+xml"}
|
87
|
+
return @client.put(u, rdf, headers)
|
88
|
+
end
|
89
|
+
|
90
|
+
def put_query_profile(qp)
|
91
|
+
if qp.is_a?(RDFObject::Resource)
|
92
|
+
rdf = qp.to_rdf_object.to_xml(4)
|
93
|
+
elsif qp.is_a?(String)
|
94
|
+
rdf = qp
|
95
|
+
end
|
96
|
+
u = build_uri("/config/queryprofiles/1")
|
97
|
+
headers = {"Content-Type" => "application/rdf+xml"}
|
98
|
+
return @client.put(u, rdf, headers)
|
99
|
+
end
|
65
100
|
|
66
101
|
def search(query, params=nil)
|
67
102
|
response = super(query, params)
|
data/lib/rdf_objects/pho.rb
CHANGED
@@ -4,7 +4,9 @@ require 'rdf_objects'
|
|
4
4
|
require 'rdf_objects/changeset'
|
5
5
|
require 'cgi'
|
6
6
|
require 'uuid'
|
7
|
+
|
7
8
|
module RDFObject
|
8
9
|
require File.dirname(__FILE__) + '/pho/store'
|
9
10
|
require File.dirname(__FILE__) + '/pho/rdf_resource'
|
11
|
+
require File.dirname(__FILE__) + '/pho/index_set'
|
10
12
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rdfobjects-pho
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ross Singer
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-12 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- LICENSE
|
60
60
|
- README
|
61
61
|
- lib/rdf_objects/pho.rb
|
62
|
+
- lib/rdf_objects/pho/index_set.rb
|
62
63
|
- lib/rdf_objects/pho/rdf_resource.rb
|
63
64
|
- lib/rdf_objects/pho/store.rb
|
64
65
|
has_rdoc: true
|