-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.rb
117 lines (89 loc) · 3.01 KB
/
sample.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
require 'rubygems'
#require 'rdf'
#require 'spira'
#require 'rdf/ntriples'
#require 'rdf/sesame'
#require 'json'
#require 'uuid'
require 'rdf-sesame-allegrograph'
url = RDF::URI("http://sed3-rdf.mitre.org:10035")
server = RDF::Sesame::Server.new(url, {:user=> 'super', :pass => 'super', :proxy_host => 'localhost', :proxy_port => 8888})
repo = server.repositories['test']
repo.initializeSpatialRepository
Spira.add_repository! :profilemanager, repo
module RDF
class HAK < Vocabulary("http://www.mitre.org/sed3/allegro/ontology#")
#datatypes
property :person
property :datafeed
property :device
#relations
property :locaiton
property :hadevice
property :area
property :name
end
end
class Device
include Spira::Resource
type RDF::HAK.device
base_uri :profilemanager
default_source :profilemanager
property :name, :predicate => FOAF.name, :type => String
end
class Person
include Spira::Resource
type RDF::HAK.person
base_uri :profilemanager
default_source :profilemanager
property :name, :predicate => FOAF.name, :type => String
property :description, :predicate => FOAF.description, :type => String
property :homepage, :predicate => FOAF.homepage, :type => String
property :nickname, :predicate => FOAF.nick, :type => String
property :location, :predicate => RDF::HAK.location, :type => RDF::Allegrograph::SphericalPoint
property :device, :predicate => RDF::HAK.hadevice, :type => :Device
end
class DataFeed
include Spira::Resource
type RDF::HAK.datafeed
default_source :profilemanager
base_uri :profilemanager
property :name, :predicate => HAK.feedname, :type => String
property :area, :predicate => HAK.area, :type => :'RDF::Allegrograph::Polygon'
end
df = DataFeed.for RDF::URI ("http://www.mitre.org/sed3/data/feeds#ied1")
df.name = "Super Awesome Data Feed #1!"
if df.area != nil
puts "AREA LOADED: #{df.area.points.inspect}"
end
df.area = RDF::Allegrograph::Polygon.new({:_subject => RDF::Allegrograph::BNode.new}, [[0,0], [80,0],[80,80],[0,80]])
df.area.save!
df.save!
person = Person.for RDF::URI("http://www.mitre.org/sed3/data/people#Danny")
person.name = "Danny"
person.description = "Programer"
person.location = RDF::Allegrograph::Point.new 20, 20
dd = Device.for(RDF::Allegrograph::BNode.new)
dd.name = "My Device"
dd.save!
person.device = dd
person.save!
puts "\n\tInside:"
puts df.area.inside RDF::HAK.location
puts 'SPARQL SAMPLE'
#val = "Medic"
#type = "<http://sed3.mitre.org/types#role>"
#query="PREFIX foaf:<http://xmlns.com/foaf/0.1/>
# PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
# PREFIX sed3:<http://sed3.mitre.org/ontology#>
# SELECT ?guidurl { ?guidurl sed3:name \""+val +"\" . ?guidurl rdf:type " +type +" }"
query = "SELECT * {?s ?p ?o}"
result = repo.sparql_query query
puts result
puts result['values'][0][0]
#df.area.destroy!
puts 'Press Enter To Delete All Statements'
gets
#Call private method to empty the database
repo.send :clear_statements
puts 'Done, Repo Empty? ' +repo.empty?.to_s