activerdf_net7 1.6.11
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +79 -0
- data/LICENSE +504 -0
- data/README.rdoc +34 -0
- data/activerdf-jena/CHANGELOG +14 -0
- data/activerdf-jena/LICENSE +504 -0
- data/activerdf-jena/README +57 -0
- data/activerdf-jena/Rakefile +87 -0
- data/activerdf-jena/TODO +18 -0
- data/activerdf-jena/VERSION +1 -0
- data/activerdf-jena/ext/antlr-2.7.5.jar +0 -0
- data/activerdf-jena/ext/arq-extra.jar +0 -0
- data/activerdf-jena/ext/arq.jar +0 -0
- data/activerdf-jena/ext/aterm-java-1.6.jar +0 -0
- data/activerdf-jena/ext/commons-logging-1.1.jar +0 -0
- data/activerdf-jena/ext/concurrent.jar +0 -0
- data/activerdf-jena/ext/icu4j_3_4.jar +0 -0
- data/activerdf-jena/ext/iri.jar +0 -0
- data/activerdf-jena/ext/jena.jar +0 -0
- data/activerdf-jena/ext/jenatest.jar +0 -0
- data/activerdf-jena/ext/json.jar +0 -0
- data/activerdf-jena/ext/junit.jar +0 -0
- data/activerdf-jena/ext/log4j-1.2.12.jar +0 -0
- data/activerdf-jena/ext/lucene-core-2.0.0.jar +0 -0
- data/activerdf-jena/ext/ng4j.jar +0 -0
- data/activerdf-jena/ext/pellet.jar +0 -0
- data/activerdf-jena/ext/relaxngDatatype.jar +0 -0
- data/activerdf-jena/ext/stax-api-1.0.jar +0 -0
- data/activerdf-jena/ext/wstx-asl-3.0.0.jar +0 -0
- data/activerdf-jena/ext/xercesImpl.jar +0 -0
- data/activerdf-jena/ext/xml-apis.jar +0 -0
- data/activerdf-jena/ext/xsdlib.jar +0 -0
- data/activerdf-jena/lib/activerdf_jena/init.rb +26 -0
- data/activerdf-jena/lib/activerdf_jena/jena.rb +59 -0
- data/activerdf-jena/lib/activerdf_jena/jena_adapter.rb +515 -0
- data/activerdf-jena/lib/activerdf_jena/lucene.rb +22 -0
- data/activerdf-jena/lib/activerdf_jena/ng4j.rb +50 -0
- data/activerdf-jena/lib/activerdf_jena/ng4j_adapter.rb +379 -0
- data/activerdf-jena/lib/activerdf_jena/pellet.rb +25 -0
- data/activerdf-jena/test/bnode_org_rss.rdf +793 -0
- data/activerdf-jena/test/eyal-foaf.nt +39 -0
- data/activerdf-jena/test/fun_with_bnodes.nt +2 -0
- data/activerdf-jena/test/s1.n3 +18 -0
- data/activerdf-jena/test/test_data.nt +32 -0
- data/activerdf-jena/test/test_jena_adapter.rb +451 -0
- data/activerdf-jena/test/test_ng4j_adapter.rb +354 -0
- data/activerdf-rdflite/CHANGELOG +31 -0
- data/activerdf-rdflite/LICENSE +504 -0
- data/activerdf-rdflite/README +16 -0
- data/activerdf-rdflite/Rakefile +73 -0
- data/activerdf-rdflite/VERSION +1 -0
- data/activerdf-rdflite/lib/activerdf_rdflite/fetching.rb +34 -0
- data/activerdf-rdflite/lib/activerdf_rdflite/init.rb +13 -0
- data/activerdf-rdflite/lib/activerdf_rdflite/rdflite.rb +582 -0
- data/activerdf-rdflite/lib/activerdf_rdflite/suggesting.rb +87 -0
- data/activerdf-rdflite/test/test_bnode_data.nt +5 -0
- data/activerdf-rdflite/test/test_data.nt +32 -0
- data/activerdf-rdflite/test/test_escaped_data.nt +2 -0
- data/activerdf-rdflite/test/test_fetching.rb +33 -0
- data/activerdf-rdflite/test/test_rdflite.rb +277 -0
- data/activerdf-redland/CHANGELOG +12 -0
- data/activerdf-redland/LICENSE +504 -0
- data/activerdf-redland/README +9 -0
- data/activerdf-redland/Rakefile +72 -0
- data/activerdf-redland/VERSION +1 -0
- data/activerdf-redland/lib/activerdf_redland/init.rb +10 -0
- data/activerdf-redland/lib/activerdf_redland/redland.rb +362 -0
- data/activerdf-redland/test/test_person_data.nt +42 -0
- data/activerdf-redland/test/test_redland_adapter.rb +242 -0
- data/activerdf-sesame/CHANGELOG +6 -0
- data/activerdf-sesame/LICENSE +10 -0
- data/activerdf-sesame/LICENSE-aduna +10 -0
- data/activerdf-sesame/LICENSE-lgpl +504 -0
- data/activerdf-sesame/README +33 -0
- data/activerdf-sesame/Rakefile +77 -0
- data/activerdf-sesame/VERSION +1 -0
- data/activerdf-sesame/ext/commons-codec-1.3.jar +0 -0
- data/activerdf-sesame/ext/commons-dbcp-1.2.2.jar +0 -0
- data/activerdf-sesame/ext/commons-httpclient-3.1.jar +0 -0
- data/activerdf-sesame/ext/commons-logging-1.1.1.jar +0 -0
- data/activerdf-sesame/ext/commons-pool-1.3.jar +0 -0
- data/activerdf-sesame/ext/commons-pool-1.5.2.jar +0 -0
- data/activerdf-sesame/ext/junit-3.8.2.jar +0 -0
- data/activerdf-sesame/ext/openrdf-sesame-2.0-onejar.jar +0 -0
- data/activerdf-sesame/ext/openrdf-sesame-2.3-pr1-onejar.jar +0 -0
- data/activerdf-sesame/ext/slf4j-api-1.4.3.jar +0 -0
- data/activerdf-sesame/ext/slf4j-nop-1.4.3.jar +0 -0
- data/activerdf-sesame/ext/wrapper-sesame2.jar +0 -0
- data/activerdf-sesame/java/build.number +3 -0
- data/activerdf-sesame/java/build.xml +313 -0
- data/activerdf-sesame/java/javadoc/allclasses-frame.html +31 -0
- data/activerdf-sesame/java/javadoc/allclasses-noframe.html +31 -0
- data/activerdf-sesame/java/javadoc/constant-values.html +146 -0
- data/activerdf-sesame/java/javadoc/deprecated-list.html +146 -0
- data/activerdf-sesame/java/javadoc/help-doc.html +223 -0
- data/activerdf-sesame/java/javadoc/index-files/index-1.html +150 -0
- data/activerdf-sesame/java/javadoc/index-files/index-10.html +145 -0
- data/activerdf-sesame/java/javadoc/index-files/index-2.html +157 -0
- data/activerdf-sesame/java/javadoc/index-files/index-3.html +146 -0
- data/activerdf-sesame/java/javadoc/index-files/index-4.html +145 -0
- data/activerdf-sesame/java/javadoc/index-files/index-5.html +145 -0
- data/activerdf-sesame/java/javadoc/index-files/index-6.html +142 -0
- data/activerdf-sesame/java/javadoc/index-files/index-7.html +145 -0
- data/activerdf-sesame/java/javadoc/index-files/index-8.html +152 -0
- data/activerdf-sesame/java/javadoc/index-files/index-9.html +146 -0
- data/activerdf-sesame/java/javadoc/index.html +36 -0
- data/activerdf-sesame/java/javadoc/org/activerdf/wrapper/sesame2/WrapperForSesame2.html +665 -0
- data/activerdf-sesame/java/javadoc/org/activerdf/wrapper/sesame2/class-use/WrapperForSesame2.html +144 -0
- data/activerdf-sesame/java/javadoc/org/activerdf/wrapper/sesame2/package-frame.html +32 -0
- data/activerdf-sesame/java/javadoc/org/activerdf/wrapper/sesame2/package-summary.html +157 -0
- data/activerdf-sesame/java/javadoc/org/activerdf/wrapper/sesame2/package-tree.html +150 -0
- data/activerdf-sesame/java/javadoc/org/activerdf/wrapper/sesame2/package-use.html +144 -0
- data/activerdf-sesame/java/javadoc/overview-summary.html +156 -0
- data/activerdf-sesame/java/javadoc/overview-tree.html +152 -0
- data/activerdf-sesame/java/javadoc/package-list +1 -0
- data/activerdf-sesame/java/javadoc/resources/inherit.gif +0 -0
- data/activerdf-sesame/java/javadoc/stylesheet.css +29 -0
- data/activerdf-sesame/java/lib/commons-codec-1.3.jar +0 -0
- data/activerdf-sesame/java/lib/commons-dbcp-1.2.2.jar +0 -0
- data/activerdf-sesame/java/lib/commons-httpclient-3.1.jar +0 -0
- data/activerdf-sesame/java/lib/commons-logging-1.1.1.jar +0 -0
- data/activerdf-sesame/java/lib/commons-pool-1.3.jar +0 -0
- data/activerdf-sesame/java/lib/commons-pool-1.5.2.jar +0 -0
- data/activerdf-sesame/java/lib/junit-3.8.2.jar +0 -0
- data/activerdf-sesame/java/lib/openrdf-sesame-2.0-onejar.jar +0 -0
- data/activerdf-sesame/java/lib/openrdf-sesame-2.3-pr1-onejar.jar +0 -0
- data/activerdf-sesame/java/lib/slf4j-api-1.4.3.jar +0 -0
- data/activerdf-sesame/java/lib/slf4j-nop-1.4.3.jar +0 -0
- data/activerdf-sesame/java/manifest.mf +3 -0
- data/activerdf-sesame/java/settings.xml +135 -0
- data/activerdf-sesame/java/src/org/activerdf/wrapper/sesame2/WrapperForSesame2.java +145 -0
- data/activerdf-sesame/java/test-src/org/activerdf/wrapper/sesame2/TestWrapperForSesame2.java +41 -0
- data/activerdf-sesame/lib/activerdf_sesame/init.rb +11 -0
- data/activerdf-sesame/lib/activerdf_sesame/sesame.rb +400 -0
- data/activerdf-sesame/test/eyal-foaf.nt +39 -0
- data/activerdf-sesame/test/eyal-foaf.rdf +65 -0
- data/activerdf-sesame/test/test_sesame_adapter.rb +341 -0
- data/activerdf-sparql/CHANGELOG +35 -0
- data/activerdf-sparql/LICENSE +504 -0
- data/activerdf-sparql/README +10 -0
- data/activerdf-sparql/Rakefile +78 -0
- data/activerdf-sparql/VERSION +1 -0
- data/activerdf-sparql/lib/activerdf_sparql/init.rb +10 -0
- data/activerdf-sparql/lib/activerdf_sparql/sparql.rb +212 -0
- data/activerdf-sparql/lib/activerdf_sparql/sparql_result_parser.rb +55 -0
- data/activerdf-sparql/test/test_sparql_adapter.rb +108 -0
- data/activerdf-yars/LICENSE +504 -0
- data/activerdf-yars/README +10 -0
- data/activerdf-yars/Rakefile +38 -0
- data/activerdf-yars/lib/activerdf_yars/init.rb +10 -0
- data/activerdf-yars/lib/activerdf_yars/jars2.rb +119 -0
- data/lib/active_rdf.rb +85 -0
- data/lib/active_rdf/directaccess/direct_access.rb +49 -0
- data/lib/active_rdf/federation/active_rdf_adapter.rb +47 -0
- data/lib/active_rdf/federation/connection_pool.rb +156 -0
- data/lib/active_rdf/federation/federation_manager.rb +112 -0
- data/lib/active_rdf/instance_exec.rb +13 -0
- data/lib/active_rdf/objectmanager/bnode.rb +7 -0
- data/lib/active_rdf/objectmanager/literal.rb +71 -0
- data/lib/active_rdf/objectmanager/namespace.rb +106 -0
- data/lib/active_rdf/objectmanager/object_manager.rb +119 -0
- data/lib/active_rdf/objectmanager/ordered_set.rb +116 -0
- data/lib/active_rdf/objectmanager/property_list.rb +76 -0
- data/lib/active_rdf/objectmanager/resource.rb +609 -0
- data/lib/active_rdf/objectmanager/resource_like.rb +28 -0
- data/lib/active_rdf/queryengine/ntriples_parser.rb +90 -0
- data/lib/active_rdf/queryengine/query.rb +245 -0
- data/lib/active_rdf/queryengine/query2jars2.rb +22 -0
- data/lib/active_rdf/queryengine/query2sparql.rb +139 -0
- data/lib/active_rdf_helpers.rb +30 -0
- data/lib/active_rdf_log.rb +100 -0
- data/test/common.rb +119 -0
- data/test/directaccess/test_direct_access.rb +64 -0
- data/test/federation/test_connection_pool.rb +86 -0
- data/test/federation/test_federation_manager.rb +145 -0
- data/test/objectmanager/test_literal.rb +52 -0
- data/test/objectmanager/test_namespace.rb +83 -0
- data/test/objectmanager/test_object_manager.rb +96 -0
- data/test/objectmanager/test_ordered_set.rb +110 -0
- data/test/objectmanager/test_resource_reading.rb +150 -0
- data/test/objectmanager/test_resource_writing.rb +39 -0
- data/test/objectmanager/test_talia_syntax.rb +68 -0
- data/test/queryengine/my_external_resource.rb +24 -0
- data/test/queryengine/test_external_resource_class.rb +49 -0
- data/test/queryengine/test_ntriples_parser.rb +71 -0
- data/test/queryengine/test_query.rb +55 -0
- data/test/queryengine/test_query2jars2.rb +51 -0
- data/test/queryengine/test_query2sparql.rb +76 -0
- data/test/queryengine/test_query_engine.rb +52 -0
- data/test/test_adapters.rb +58 -0
- metadata +266 -0
@@ -0,0 +1,87 @@
|
|
1
|
+
# Author:: Eyal Oren
|
2
|
+
# Copyright:: (c) 2005-2006 Eyal Oren
|
3
|
+
# License:: LGPL
|
4
|
+
|
5
|
+
# The SuggestingAdapter is an extension to rdflite that can recommand
|
6
|
+
# additional predicates for a given resource, based on usage statistics in the
|
7
|
+
# whole dataset. E.g. given a dataset with FOAF data, one can ask a suggestion
|
8
|
+
# for a person and get a recommendation for this person to also use
|
9
|
+
# foaf:birthday. You can use this adapter in any collaborative editing setting:
|
10
|
+
# it leads the community to converge on terminology (everybody will use the
|
11
|
+
# same foaf:birthday to define somebody's birthday).
|
12
|
+
class SuggestingAdapter < FetchingAdapter
|
13
|
+
ConnectionPool.register_adapter(:suggesting,self)
|
14
|
+
|
15
|
+
alias _old_initialize initialize
|
16
|
+
|
17
|
+
# initialises the adapter, see RDFLite for description of possible parameters.
|
18
|
+
def initialize params
|
19
|
+
_old_initialize(params)
|
20
|
+
@db.execute('drop view if exists occurrence')
|
21
|
+
@db.execute('create view occurrence as select p, count(distinct s) as count from triple group by p')
|
22
|
+
|
23
|
+
@db.execute('drop view if exists cooccurrence')
|
24
|
+
@db.execute('create view cooccurrence as select t0.p as p1,t1.p as p2, count(distinct t0.s) as count from triple as t0 join triple as t1 on t0.s=t1.s and t0.p!=t1.p group by t0.p, t1.p')
|
25
|
+
end
|
26
|
+
|
27
|
+
# suggests additional predicates that might be applicable for the given resource
|
28
|
+
def suggest(resource)
|
29
|
+
ActiveRdfLogger::log_debug(self) { "Starting suggestions for #{size} triples" }
|
30
|
+
time = Time.now
|
31
|
+
|
32
|
+
predicates = []
|
33
|
+
own_predicates = resource.direct_predicates
|
34
|
+
|
35
|
+
construct_occurrence_matrix
|
36
|
+
construct_cooccurrence_matrix
|
37
|
+
|
38
|
+
own_predicates.each do |p|
|
39
|
+
predicates << p if occurrence(p) > 1
|
40
|
+
end
|
41
|
+
|
42
|
+
# fetch all predicates co-occurring with our predicates
|
43
|
+
candidates = predicates.collect {|p| cooccurring(p) }
|
44
|
+
return nil if candidates.empty?
|
45
|
+
|
46
|
+
# perform set intersection
|
47
|
+
candidates = candidates.inject {|intersect, n| intersect & n }.flatten
|
48
|
+
candidates = candidates - own_predicates
|
49
|
+
|
50
|
+
suggestions = candidates.collect do |candidate|
|
51
|
+
score = predicates.inject(1.0) do |score, p|
|
52
|
+
score * cooccurrence(candidate, p) / occurrence(p)
|
53
|
+
end
|
54
|
+
[candidate, score]
|
55
|
+
end
|
56
|
+
ActiveRdfLogger::log_debug(self) { "Suggestions for #{resource} took #{Time.now-time}s" }
|
57
|
+
suggestions
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
def construct_occurrence_matrix
|
62
|
+
@occurrence = {}
|
63
|
+
@db.execute('select * from occurrence where count > 1') do |p,count|
|
64
|
+
@occurrence[parse(p)] = count.to_i
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def construct_cooccurrence_matrix
|
69
|
+
@cooccurrence = {}
|
70
|
+
@db.execute('select * from cooccurrence') do |p1, p2, count|
|
71
|
+
@cooccurrence[parse(p1)] ||= {}
|
72
|
+
@cooccurrence[parse(p1)][parse(p2)] = count.to_i
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def occurrence(predicate)
|
77
|
+
@occurrence[predicate] || 0
|
78
|
+
end
|
79
|
+
|
80
|
+
def cooccurrence(p1, p2)
|
81
|
+
@cooccurrence[p1][p2] || 0
|
82
|
+
end
|
83
|
+
|
84
|
+
def cooccurring(predicate)
|
85
|
+
@cooccurrence[predicate].keys
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
_:1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://activerdf.org/test/Person> .
|
2
|
+
_:1 <http://activerdf.org/test/age> "27" .
|
3
|
+
_:1 <http://activerdf.org/test/name> "Eyal Oren" .
|
4
|
+
_:2 <http://activerdf.org/test/age> "27" .
|
5
|
+
_:2 <http://activerdf.org/test/eye> "blue" .
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<http://activerdf.org/test/Person> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
|
2
|
+
<http://activerdf.org/test/Person> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Resource> .
|
3
|
+
<http://activerdf.org/test/Person> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://www.w3.org/2000/01/rdf-schema#Resource> .
|
4
|
+
<http://activerdf.org/test/age> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/1999/02/22-rdf-syntax-ns#Property> .
|
5
|
+
<http://activerdf.org/test/age> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Resource> .
|
6
|
+
<http://activerdf.org/test/age> <http://www.w3.org/2000/01/rdf-schema#domain> <http://activerdf.org/test/Person> .
|
7
|
+
<http://activerdf.org/test/age> <http://www.w3.org/2000/01/rdf-schema#domain> <http://www.w3.org/2000/01/rdf-schema#Resource> .
|
8
|
+
<http://activerdf.org/test/age> <http://www.w3.org/2000/01/rdf-schema#range> <http://www.w3.org/1999/02/22-rdf-syntax-ns#Literal> .
|
9
|
+
<http://activerdf.org/test/car> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/1999/02/22-rdf-syntax-ns#Property> .
|
10
|
+
<http://activerdf.org/test/car> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Resource> .
|
11
|
+
<http://activerdf.org/test/car> <http://www.w3.org/2000/01/rdf-schema#domain> <http://activerdf.org/test/Person> .
|
12
|
+
<http://activerdf.org/test/car> <http://www.w3.org/2000/01/rdf-schema#domain> <http://www.w3.org/2000/01/rdf-schema#Resource> .
|
13
|
+
<http://activerdf.org/test/car> <http://www.w3.org/2000/01/rdf-schema#range> <http://www.w3.org/1999/02/22-rdf-syntax-ns#Literal> .
|
14
|
+
<http://activerdf.org/test/eyal> <http://activerdf.org/test/age> "27" .
|
15
|
+
<http://activerdf.org/test/eyal> <http://activerdf.org/test/eye> "blue" .
|
16
|
+
<http://activerdf.org/test/eyal> <http://activerdf.org/test/name> "Eyal Oren" .
|
17
|
+
<http://activerdf.org/test/eyal> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://activerdf.org/test/Person> .
|
18
|
+
<http://activerdf.org/test/eyal> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Resource> .
|
19
|
+
<http://activerdf.org/test/eye> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/1999/02/22-rdf-syntax-ns#Property> .
|
20
|
+
<http://activerdf.org/test/eye> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Resource> .
|
21
|
+
<http://activerdf.org/test/eye> <http://www.w3.org/2000/01/rdf-schema#domain> <http://activerdf.org/test/Person> .
|
22
|
+
<http://activerdf.org/test/eye> <http://www.w3.org/2000/01/rdf-schema#domain> <http://www.w3.org/2000/01/rdf-schema#Resource> .
|
23
|
+
<http://activerdf.org/test/eye> <http://www.w3.org/2000/01/rdf-schema#range> <http://www.w3.org/1999/02/22-rdf-syntax-ns#Literal> .
|
24
|
+
<http://www.w3.org/1999/02/22-rdf-syntax-ns#Property> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
|
25
|
+
<http://www.w3.org/1999/02/22-rdf-syntax-ns#Property> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Resource> .
|
26
|
+
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#domain> <http://www.w3.org/2000/01/rdf-schema#Resource> .
|
27
|
+
<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#range> <http://www.w3.org/2000/01/rdf-schema#Class> .
|
28
|
+
<http://www.w3.org/2000/01/rdf-schema#Class> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
|
29
|
+
<http://www.w3.org/2000/01/rdf-schema#Class> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Resource> .
|
30
|
+
_:#1 <http://activerdf.org/test/age> "29" .
|
31
|
+
_:#1 <http://activerdf.org/test/name> "Another Person" .
|
32
|
+
_:#1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://activerdf.org/test/Person> .
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Author:: Eyal Oren
|
2
|
+
# Copyright:: (c) 2005-2006
|
3
|
+
# License:: LGPL
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'test/unit'
|
7
|
+
require 'active_rdf'
|
8
|
+
|
9
|
+
class TestFetchingAdapter < Test::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
ConnectionPool.clear
|
12
|
+
@adapter = ConnectionPool.add(:type => :fetching)
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_parse_foaf
|
19
|
+
@adapter.fetch("http://eyaloren.org/foaf.rdf#me")
|
20
|
+
assert @adapter.size > 0
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_sioc_schema
|
24
|
+
@adapter.fetch("http://rdfs.org/sioc/ns#")
|
25
|
+
assert_equal 560, @adapter.size
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_foaf_schema
|
29
|
+
@adapter.fetch("http://xmlns.com/foaf/0.1/")
|
30
|
+
# foaf contains 563 triples but with two duplicates
|
31
|
+
assert_equal 561, @adapter.size
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,277 @@
|
|
1
|
+
å# Author:: Eyal Oren
|
2
|
+
# Copyright:: (c) 2005-2006
|
3
|
+
# License:: LGPL
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'test/unit'
|
7
|
+
require 'active_rdf'
|
8
|
+
require 'federation/federation_manager'
|
9
|
+
require 'queryengine/query'
|
10
|
+
|
11
|
+
class TestRdfLiteAdapter < Test::Unit::TestCase
|
12
|
+
def setup
|
13
|
+
ConnectionPool.clear
|
14
|
+
end
|
15
|
+
|
16
|
+
def teardown
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_registration
|
20
|
+
adapter = ConnectionPool.add_data_source(:type => :rdflite)
|
21
|
+
assert_instance_of RDFLite, adapter
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_initialise
|
25
|
+
adapter = ConnectionPool.add_data_source(:type => :rdflite, :keyword => false)
|
26
|
+
assert !adapter.keyword_search?
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_duplicate_registration
|
30
|
+
adapter1 = ConnectionPool.add_data_source(:type => :rdflite)
|
31
|
+
adapter2 = ConnectionPool.add_data_source(:type => :rdflite)
|
32
|
+
|
33
|
+
assert_equal adapter1, adapter2
|
34
|
+
assert_equal adapter1.object_id, adapter2.object_id
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_simple_query
|
38
|
+
adapter = ConnectionPool.add_data_source(:type => :rdflite)
|
39
|
+
|
40
|
+
eyal = RDFS::Resource.new 'eyaloren.org'
|
41
|
+
age = RDFS::Resource.new 'foaf:age'
|
42
|
+
test = RDFS::Resource.new 'test'
|
43
|
+
|
44
|
+
adapter.add(eyal, age, test)
|
45
|
+
|
46
|
+
result = Query.new.distinct(:s).where(:s, :p, :o).execute(:flatten => true)
|
47
|
+
assert_instance_of RDFS::Resource, result
|
48
|
+
assert_equal 'eyaloren.org', result.uri
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_escaped_literals
|
52
|
+
adapter = ConnectionPool.add_data_source(:type => :rdflite)
|
53
|
+
eyal = RDFS::Resource.new 'eyal'
|
54
|
+
comment = RDFS::Resource.new 'comment'
|
55
|
+
string = 'test\nbreak\"quoted\"'
|
56
|
+
interpreted = "test\nbreak\"quoted\""
|
57
|
+
|
58
|
+
adapter.add(eyal, comment, string)
|
59
|
+
assert_equal interpreted, eyal.comment
|
60
|
+
|
61
|
+
description = RDFS::Resource.new 'description'
|
62
|
+
string = 'ümlaut and \u00ebmlaut'
|
63
|
+
interpreted = "ümlaut and ëmlaut"
|
64
|
+
|
65
|
+
adapter.add(eyal, description, string)
|
66
|
+
assert_equal interpreted, eyal.description
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_load_escaped_literals
|
70
|
+
adapter = ConnectionPool.add_data_source(:type => :rdflite)
|
71
|
+
adapter.load(File.dirname(File.expand_path(__FILE__)) + '/test_escaped_data.nt')
|
72
|
+
eyal = RDFS::Resource.new('http://activerdf.org/test/eyal')
|
73
|
+
|
74
|
+
assert_equal 2, adapter.size
|
75
|
+
assert_equal "ümlauts and ëmlauts", eyal.comment
|
76
|
+
assert_equal "line\nbreaks, <p>'s and \"quotes\"", eyal.encoded
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_federated_query
|
80
|
+
adapter1 = ConnectionPool.add_data_source(:type => :rdflite)
|
81
|
+
adapter2 = ConnectionPool.add_data_source(:type => :rdflite, :fake_symbol_to_get_unique_adapter => true)
|
82
|
+
|
83
|
+
eyal = RDFS::Resource.new 'eyaloren.org'
|
84
|
+
age = RDFS::Resource.new 'foaf:age'
|
85
|
+
test = RDFS::Resource.new 'test'
|
86
|
+
test2 = RDFS::Resource.new 'test2'
|
87
|
+
|
88
|
+
adapter1.add(eyal, age, test)
|
89
|
+
adapter2.add(eyal, age, test2)
|
90
|
+
|
91
|
+
# assert only one distinct subject is found (same one in both adapters)
|
92
|
+
assert_equal 1, Query.new.distinct(:s).where(:s, :p, :o).execute.size
|
93
|
+
|
94
|
+
# assert two distinct objects are found
|
95
|
+
results = Query.new.distinct(:o).where(:s, :p, :o).execute
|
96
|
+
assert_equal 2, results.size
|
97
|
+
|
98
|
+
results.all? {|result| assert result.instance_of?(RDFS::Resource) }
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_query_with_block
|
102
|
+
adapter = ConnectionPool.add_data_source(:type => :rdflite)
|
103
|
+
|
104
|
+
eyal = RDFS::Resource.new 'eyaloren.org'
|
105
|
+
age = RDFS::Resource.new 'foaf:age'
|
106
|
+
test = RDFS::Resource.new 'test'
|
107
|
+
|
108
|
+
adapter.add(eyal, age, test)
|
109
|
+
Query.new.select(:s,:p).where(:s,:p,:o).execute(:flatten => false) do |s,p|
|
110
|
+
assert_equal 'eyaloren.org', s.uri
|
111
|
+
assert_equal 'foaf:age', p.uri
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_loading_data
|
116
|
+
adapter = ConnectionPool.add_data_source :type => :rdflite
|
117
|
+
adapter.load(File.dirname(File.expand_path(__FILE__)) + '/test_data.nt')
|
118
|
+
assert_equal 32, adapter.size
|
119
|
+
|
120
|
+
adapter.clear
|
121
|
+
adapter.load('http://www.w3.org/2000/10/rdf-tests/rdfcore/ntriples/test.nt')
|
122
|
+
assert_equal 30, adapter.size
|
123
|
+
|
124
|
+
adapter.clear
|
125
|
+
adapter.load('http://www.w3.org/2000/10/rdf-tests/rdfcore/testSchema.rdf')
|
126
|
+
assert_equal 76, adapter.size
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_load_bnodes
|
130
|
+
adapter = ConnectionPool.add_data_source :type => :rdflite
|
131
|
+
adapter.load(File.dirname(File.expand_path(__FILE__)) + '/test_bnode_data.nt')
|
132
|
+
|
133
|
+
# loaded five triples in total
|
134
|
+
assert_equal 5, adapter.size
|
135
|
+
|
136
|
+
# triples contain two distinct bnodes
|
137
|
+
assert_equal 2, Query.new.count.distinct(:s).where(:s,:p,:o).execute
|
138
|
+
|
139
|
+
# collecting the bnodes
|
140
|
+
bnodes = Query.new.distinct(:s).where(:s,:p,:o).execute
|
141
|
+
# assert that _:#1 occurs in three triples
|
142
|
+
assert_equal 3, Query.new.select(:p,:o).where(bnodes[0], :p, :o).execute.size
|
143
|
+
# assert that _:#2 occurs in two triples
|
144
|
+
assert_equal 2, Query.new.select(:p,:o).where(bnodes[1], :p, :o).execute.size
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_count_query
|
148
|
+
adapter = ConnectionPool.add_data_source :type => :rdflite
|
149
|
+
adapter.load(File.dirname(File.expand_path(__FILE__)) + '/test_data.nt')
|
150
|
+
assert_kind_of Fixnum, Query.new.count(:s).where(:s,:p,:o).execute
|
151
|
+
assert_equal 32, Query.new.count(:s).where(:s,:p,:o).execute
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_single_context
|
155
|
+
adapter = ConnectionPool.add_data_source :type => :rdflite
|
156
|
+
file = File.dirname(File.expand_path(__FILE__)) + '/test_data.nt'
|
157
|
+
adapter.load(file)
|
158
|
+
|
159
|
+
context = Query.new.distinct(:c).where(:s,:p,:o,:c).execute(:flatten => true)
|
160
|
+
assert_instance_of RDFS::Resource, context
|
161
|
+
assert_equal RDFS::Resource.new("file:#{file}"), context
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_multiple_context
|
165
|
+
adapter = ConnectionPool.add_data_source :type => :rdflite
|
166
|
+
file = File.dirname(File.expand_path(__FILE__)) + '/test_data.nt'
|
167
|
+
adapter.load(file)
|
168
|
+
file_context = RDFS::Resource.new("file:#{file}")
|
169
|
+
|
170
|
+
eyal = RDFS::Resource.new 'eyaloren.org'
|
171
|
+
age = RDFS::Resource.new 'foaf:age'
|
172
|
+
test = RDFS::Resource.new 'test'
|
173
|
+
adapter.add(eyal, age, test, 'context')
|
174
|
+
|
175
|
+
context = Query.new.distinct(:c).where(:s,:p,:o,:c).execute
|
176
|
+
assert_equal file_context, context[0]
|
177
|
+
assert_equal 'context', context[1]
|
178
|
+
|
179
|
+
assert_equal 10, Query.new.count.distinct(:s).where(:s, :p, :o, nil).execute
|
180
|
+
assert_equal 1, Query.new.count.distinct(:s).where(:s, :p, :o, 'context').execute
|
181
|
+
assert_equal 9, Query.new.count.distinct(:s).where(:s, :p, :o, file_context).execute
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_person_data
|
185
|
+
adapter = ConnectionPool.add_data_source :type => :rdflite
|
186
|
+
adapter.load(File.dirname(File.expand_path(__FILE__)) + '/test_data.nt')
|
187
|
+
|
188
|
+
Namespace.register(:test, 'http://activerdf.org/test/')
|
189
|
+
eyal = Namespace.lookup(:test, :eyal)
|
190
|
+
eye = Namespace.lookup(:test, :eye)
|
191
|
+
person = Namespace.lookup(:test, :Person)
|
192
|
+
type = Namespace.lookup(:rdf, :type)
|
193
|
+
resource = Namespace.lookup(:rdfs,:resource)
|
194
|
+
|
195
|
+
color = Query.new.select(:o).where(eyal, eye,:o).execute(:flatten => true)
|
196
|
+
assert 'blue', color
|
197
|
+
assert_instance_of String, color
|
198
|
+
|
199
|
+
ObjectManager.construct_classes
|
200
|
+
assert eyal.instance_of?(TEST::Person)
|
201
|
+
assert eyal.instance_of?(RDFS::Resource)
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_delete_data
|
205
|
+
adapter = ConnectionPool.add_data_source :type => :rdflite
|
206
|
+
adapter.load(File.dirname(File.expand_path(__FILE__)) + '/test_data.nt')
|
207
|
+
assert_equal 32, adapter.size
|
208
|
+
|
209
|
+
eyal = RDFS::Resource.new('http://activerdf.org/test/eyal')
|
210
|
+
adapter.delete(eyal, nil, nil)
|
211
|
+
assert_equal 27, adapter.size
|
212
|
+
|
213
|
+
adapter.delete(nil, nil, nil)
|
214
|
+
assert_equal 0, adapter.size
|
215
|
+
end
|
216
|
+
|
217
|
+
def test_keyword_search
|
218
|
+
adapter = ConnectionPool.add_data_source :type => :rdflite
|
219
|
+
adapter.load(File.dirname(File.expand_path(__FILE__)) + '/test_data.nt')
|
220
|
+
|
221
|
+
eyal = RDFS::Resource.new('http://activerdf.org/test/eyal')
|
222
|
+
|
223
|
+
# we cant garantuee that ferret is installed
|
224
|
+
if adapter.keyword_search?
|
225
|
+
assert_equal eyal, Query.new.distinct(:s).where(:s,:keyword,"blue").execute(:flatten => true)
|
226
|
+
assert_equal eyal, Query.new.distinct(:s).where(:s,:keyword,"27").execute(:flatten => true)
|
227
|
+
assert_equal eyal, Query.new.distinct(:s).where(:s,:keyword,"eyal oren").execute(:flatten => true)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
def test_bnodes
|
232
|
+
adapter = ConnectionPool.add_data_source :type => :rdflite
|
233
|
+
adapter.load(File.dirname(File.expand_path(__FILE__)) + '/test_data.nt')
|
234
|
+
|
235
|
+
Namespace.register(:test, 'http://activerdf.org/test/')
|
236
|
+
ObjectManager.construct_classes
|
237
|
+
assert_equal 2, TEST::Person.find_all.size
|
238
|
+
assert_equal 29, TEST::Person.find_all[1].age.to_i
|
239
|
+
assert_equal "Another Person", TEST::Person.find_all[1].name
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_multi_join
|
243
|
+
adapter = ConnectionPool.add_data_source :type => :rdflite
|
244
|
+
type = Namespace.lookup(:rdf, 'type')
|
245
|
+
transProp = Namespace.lookup(:owl, 'TransitiveProperty')
|
246
|
+
|
247
|
+
Namespace.register(:test, 'http://test.com/')
|
248
|
+
ancestor = Namespace.lookup(:test, 'ancestor')
|
249
|
+
sue = Namespace.lookup(:test, 'Sue')
|
250
|
+
mary = Namespace.lookup(:test, 'Mary')
|
251
|
+
anne = Namespace.lookup(:test, 'Anne')
|
252
|
+
|
253
|
+
adapter.add ancestor, type, transProp
|
254
|
+
adapter.add sue, ancestor, mary
|
255
|
+
adapter.add mary, ancestor, anne
|
256
|
+
|
257
|
+
# test that query with multi-join (joining over 1.p==2.p and 1.o==2.s) works
|
258
|
+
query = Query.new.select(:Sue, :p, :Anne)
|
259
|
+
query.where(:p, type, transProp)
|
260
|
+
query.where(:Sue, :p, :Mary)
|
261
|
+
query.where(:Mary, :p, :Anne)
|
262
|
+
assert_equal 1, query.execute.size
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_limit_and_offset
|
266
|
+
adapter = ConnectionPool.add_data_source :type => :rdflite
|
267
|
+
adapter.load(File.dirname(File.expand_path(__FILE__)) + '/test_data.nt')
|
268
|
+
Namespace.register(:test, 'http://activerdf.org/test/')
|
269
|
+
|
270
|
+
assert_equal 7, RDFS::Resource.find(:all).size
|
271
|
+
assert_equal 5, RDFS::Resource.find(:all, :limit => 5).size
|
272
|
+
assert_equal 4, RDFS::Resource.find(:all, :limit => 4, :offset => 3).size
|
273
|
+
assert RDFS::Resource.find(:all, :limit => 4, :offset => 3) != RDFS::Resource.find(:all, :limit => 4)
|
274
|
+
|
275
|
+
assert_equal [TEST::eyal, TEST::age, TEST::car], RDFS::Resource.find(:all, :limit => 3, :order => RDF::type)
|
276
|
+
end
|
277
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
== activerdf_redland (1.2.3)
|
2
|
+
* fixed adapter#delete (Richard Dale)
|
3
|
+
|
4
|
+
== activerdf_redland (1.2.2) Tue, 16 Sep 2008 12:44:39 +0200
|
5
|
+
* added close and clear method
|
6
|
+
* added support for full Redland options (Benno Blumenthal)
|
7
|
+
|
8
|
+
== activerdf_redland (1.2.1) Sat Jun 23 09:03:43 UTC 2007
|
9
|
+
* added support for Redland on PostgreSQL (Richard Dale)
|
10
|
+
|
11
|
+
== activerdf_redland (1.2) Mon, 05 Mar 2007 20:40:55 +0000
|
12
|
+
* added loading from remote URL (Benno Blumenthal)
|