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,52 @@
|
|
1
|
+
# Author:: Eyal Oren
|
2
|
+
# Copyright:: (c) 2005-2006
|
3
|
+
# License:: LGPL
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'active_rdf'
|
7
|
+
require "#{File.dirname(__FILE__)}/../common"
|
8
|
+
|
9
|
+
class TestLiteral < Test::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
ConnectionPool.clear
|
12
|
+
@adapter = get_adapter
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_xsd_string
|
19
|
+
test = Literal.typed('test', XSD::string)
|
20
|
+
assert_equal '"test"^^<http://www.w3.org/2001/XMLSchema#string>', test.to_ntriple
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_automatic_conversion
|
24
|
+
# infer string
|
25
|
+
test = 'test'
|
26
|
+
assert_equal '"test"^^<http://www.w3.org/2001/XMLSchema#string>', test.to_ntriple
|
27
|
+
|
28
|
+
# infer integer
|
29
|
+
test = 18
|
30
|
+
assert_equal '"18"^^<http://www.w3.org/2001/XMLSchema#integer>', test.to_ntriple
|
31
|
+
|
32
|
+
# infer boolean
|
33
|
+
test = true
|
34
|
+
assert_equal '"true"^^<http://www.w3.org/2001/XMLSchema#boolean>', test.to_ntriple
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_equality
|
38
|
+
test1 = 'test'
|
39
|
+
test2 = Literal.typed('test', XSD::string)
|
40
|
+
assert_equal test2.to_ntriple, test1.to_ntriple
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_language_tag
|
44
|
+
cat = 'cat'
|
45
|
+
cat_en = LocalizedString.new('cat', '@en')
|
46
|
+
assert_equal '"cat"@en', cat_en.to_ntriple
|
47
|
+
assert_not_equal cat.to_ntriple, cat_en.to_ntriple
|
48
|
+
|
49
|
+
assert_equal '"dog"@en-GB', LocalizedString.new('dog', '@en-GB').to_ntriple
|
50
|
+
assert_equal '"dog"@en@test', LocalizedString.new('dog', '@en@test').to_ntriple
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# Author:: Eyal Oren
|
2
|
+
# Copyright:: (c) 2005-2006
|
3
|
+
# License:: LGPL
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'active_rdf'
|
7
|
+
require 'objectmanager/namespace'
|
8
|
+
require "#{File.dirname(__FILE__)}/../common"
|
9
|
+
|
10
|
+
class TestNamespace < Test::Unit::TestCase
|
11
|
+
Rdf = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
|
12
|
+
Rdfs = 'http://www.w3.org/2000/01/rdf-schema#'
|
13
|
+
RdfType = RDFS::Resource.new('http://www.w3.org/1999/02/22-rdf-syntax-ns#type')
|
14
|
+
RdfsResource = RDFS::Resource.new('http://www.w3.org/2000/01/rdf-schema#Resource')
|
15
|
+
|
16
|
+
def setup
|
17
|
+
end
|
18
|
+
|
19
|
+
def teardown
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_default_ns_expansion
|
23
|
+
rdftype = RdfType
|
24
|
+
rdfsresource = RdfsResource
|
25
|
+
|
26
|
+
assert_equal rdftype, RDF::type
|
27
|
+
assert_equal rdftype, Namespace.lookup(:rdf, :type)
|
28
|
+
assert_equal rdftype, Namespace.lookup(:rdf, 'type')
|
29
|
+
assert_equal rdftype, Namespace.lookup('rdf', :type)
|
30
|
+
assert_equal rdftype, Namespace.lookup('rdf', 'type')
|
31
|
+
|
32
|
+
assert_equal rdfsresource, RDFS::Resource
|
33
|
+
assert_equal rdfsresource, Namespace.lookup(:rdfs, :Resource)
|
34
|
+
assert_equal rdfsresource, Namespace.lookup(:rdfs, 'Resource')
|
35
|
+
assert_equal rdfsresource, Namespace.lookup('rdfs', :Resource)
|
36
|
+
assert_equal rdfsresource, Namespace.lookup('rdfs', 'Resource')
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_registration_of_rdf_and_rdfs
|
40
|
+
rdftype = RDFS::Resource.new RdfType
|
41
|
+
rdfsresource = RDFS::Resource.new RdfsResource
|
42
|
+
|
43
|
+
assert_equal rdftype, RDF::type
|
44
|
+
assert_equal rdfsresource, RDFS::Resource
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_find_prefix
|
48
|
+
assert_equal :rdf, Namespace.prefix(Namespace.lookup(:rdf, :type))
|
49
|
+
assert_equal :rdf, Namespace.prefix(Namespace.expand(:rdf, :type))
|
50
|
+
|
51
|
+
assert_equal :rdfs, Namespace.prefix(Namespace.lookup(:rdfs, :Resource))
|
52
|
+
assert_equal :rdfs, Namespace.prefix(Namespace.expand(:rdfs, :Resource))
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_class_localname
|
56
|
+
assert_equal 'type', Namespace.lookup(:rdf, :type).localname
|
57
|
+
assert_equal 'type', RDF::type.localname
|
58
|
+
|
59
|
+
assert_equal 'Class', Namespace.lookup(:rdfs, :Class).localname
|
60
|
+
assert_equal 'Class', RDFS::Class.localname
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_class_register
|
64
|
+
test = 'http://test.org/'
|
65
|
+
abc = RDFS::Resource.new("#{test}abc")
|
66
|
+
Namespace.register :test, test
|
67
|
+
|
68
|
+
assert_equal abc, Namespace.lookup(:test, :abc)
|
69
|
+
assert_equal abc, TEST::abc
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_attributes
|
73
|
+
assert_nothing_raised { RDFS::domain }
|
74
|
+
assert_nothing_raised { RDF::type }
|
75
|
+
assert_raise(NameError) { FOAF::type }
|
76
|
+
|
77
|
+
foaf = 'http://xmlns.com/foaf/0.1/'
|
78
|
+
Namespace.register :foaf, foaf
|
79
|
+
|
80
|
+
foafname = RDFS::Resource.new(foaf + 'name')
|
81
|
+
assert_equal foafname, FOAF::name
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# Author:: Eyal Oren
|
2
|
+
# Copyright:: (c) 2005-2006
|
3
|
+
# License:: LGPL
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'active_rdf'
|
7
|
+
require "#{File.dirname(__FILE__)}/../common"
|
8
|
+
|
9
|
+
class TestObjectManager < Test::Unit::TestCase
|
10
|
+
def setup
|
11
|
+
ConnectionPool.clear
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_resource_creation
|
18
|
+
assert_nothing_raised { RDFS::Resource.new('abc') }
|
19
|
+
|
20
|
+
r1 = RDFS::Resource.new('abc')
|
21
|
+
r2 = RDFS::Resource.new('cde')
|
22
|
+
r3 = RDFS::Resource.new('cde')
|
23
|
+
assert_equal r3, RDFS::Resource.new(r3)
|
24
|
+
assert_equal r3, RDFS::Resource.new(r3.to_s)
|
25
|
+
|
26
|
+
assert_equal 'abc', r1.uri
|
27
|
+
assert_equal 'cde', r2.uri
|
28
|
+
assert_equal r3, r2
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_class_construct_classes
|
32
|
+
adapter = get_write_adapter
|
33
|
+
adapter.load "#{File.dirname(__FILE__)}/../test_person_data.nt"
|
34
|
+
|
35
|
+
Namespace.register(:test, 'http://activerdf.org/test/')
|
36
|
+
|
37
|
+
assert_equal RDFS::Resource.new('http://activerdf.org/test/Person'), TEST::Person
|
38
|
+
assert_kind_of Class, TEST::Person
|
39
|
+
assert TEST::Person.ancestors.include?(RDFS::Resource)
|
40
|
+
assert_instance_of TEST::Person, TEST::Person.new('')
|
41
|
+
assert TEST::Person.new('').respond_to?(:uri)
|
42
|
+
|
43
|
+
assert_equal RDFS::Resource.new('http://www.w3.org/2000/01/rdf-schema#Class'), RDFS::Class
|
44
|
+
assert RDFS::Class.ancestors.include?(RDFS::Resource)
|
45
|
+
assert_kind_of Class, RDFS::Class
|
46
|
+
assert_instance_of RDFS::Resource, RDFS::Class.new('')
|
47
|
+
assert RDFS::Class.new('').respond_to?(:uri)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_custom_code
|
51
|
+
Namespace.register(:test, 'http://activerdf.org/test/')
|
52
|
+
|
53
|
+
TEST::Person.module_eval{ def hello; 'world'; end }
|
54
|
+
assert_respond_to TEST::Person.new(''), :hello
|
55
|
+
assert_equal 'world', TEST::Person.new('').hello
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_class_uri
|
59
|
+
adapter = get_write_adapter
|
60
|
+
adapter.load "#{File.dirname(__FILE__)}/../test_person_data.nt"
|
61
|
+
Namespace.register(:test, 'http://activerdf.org/test/')
|
62
|
+
|
63
|
+
assert_equal RDFS::Resource.new('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), RDF::type
|
64
|
+
assert_equal RDF::type, RDFS::Resource.new('http://www.w3.org/1999/02/22-rdf-syntax-ns#type')
|
65
|
+
assert_equal TEST::Person, RDFS::Resource.new('http://activerdf.org/test/Person')
|
66
|
+
assert_equal RDFS::Resource.new('http://activerdf.org/test/Person'), TEST::Person
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_to_xml
|
70
|
+
get_adapter.load "#{File.dirname(__FILE__)}/../test_person_data.nt"
|
71
|
+
Namespace.register(:test, 'http://activerdf.org/test/')
|
72
|
+
|
73
|
+
eyal = RDFS::Resource.new 'http://activerdf.org/test/eyal'
|
74
|
+
eyal.age = 29
|
75
|
+
assert_equal 29, eyal.age
|
76
|
+
snippet =
|
77
|
+
'<rdf:Description rdf:about="#eyal">
|
78
|
+
<test:age rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">29</test:age>
|
79
|
+
<test:eye rdf:datatype="http://www.w3.org/2001/XMLSchema#string">blue</test:eye>
|
80
|
+
<rdf:type rdf:resource="http://activerdf.org/test/Person"/>
|
81
|
+
<rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Resource"/>
|
82
|
+
</rdf:Description>
|
83
|
+
</rdf:RDF>'
|
84
|
+
# Ignore whitespaces in comparison
|
85
|
+
assert eyal.to_xml.gsub!(/\s+/, '').include?(snippet.gsub!(/\s+/, ''))
|
86
|
+
|
87
|
+
require 'net/http'
|
88
|
+
url = 'http://librdf.org/parse'
|
89
|
+
uri = URI.parse(url)
|
90
|
+
req = Net::HTTP::Post.new(url)
|
91
|
+
req.set_form_data('content'=>eyal.to_xml, 'language'=>'rdfxml')
|
92
|
+
res = Net::HTTP.new(uri.host,uri.port).start {|http| http.request(req) }
|
93
|
+
result = res.body.match(/Found.*triples/)[0]
|
94
|
+
assert_equal "Found 4 triples", result, 'invalid XML generated (according to online parser at librdf.org'
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
#
|
2
|
+
# To change this template, choose Tools | Templates
|
3
|
+
# and open the template in the editor.
|
4
|
+
|
5
|
+
|
6
|
+
require 'test/unit'
|
7
|
+
require 'active_rdf'
|
8
|
+
require "#{File.dirname(__FILE__)}/../common"
|
9
|
+
require 'objectmanager/ordered_set'
|
10
|
+
|
11
|
+
class TestOrderedSet < Test::Unit::TestCase
|
12
|
+
|
13
|
+
def setup
|
14
|
+
ConnectionPool.clear
|
15
|
+
|
16
|
+
adapter = get_write_adapter
|
17
|
+
adapter.load "#{File.dirname(__FILE__)}/../test_person_data.nt"
|
18
|
+
adapter.load "#{File.dirname(__FILE__)}/../test_rdf_data.nt"
|
19
|
+
ObjectManager.construct_classes
|
20
|
+
|
21
|
+
@ordered_set = OrderedSet.new('http://activerdf.org/test/ordered_set')
|
22
|
+
|
23
|
+
@item_1 = RDFS::Resource.new 'http://activerdf.org/test/item_1'
|
24
|
+
@item_2 = RDFS::Resource.new 'http://activerdf.org/test/item_2'
|
25
|
+
@item_3 = RDFS::Resource.new 'http://activerdf.org/test/item_3'
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_resource_type
|
29
|
+
assert_kind_of OrderedSet, @ordered_set
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_query
|
33
|
+
# add items to container
|
34
|
+
@ordered_set.add @item_1
|
35
|
+
@ordered_set.add @item_2
|
36
|
+
@ordered_set.add @item_3
|
37
|
+
|
38
|
+
# check if all items are inserted
|
39
|
+
assert_equal 3, @ordered_set.elements.size
|
40
|
+
|
41
|
+
# check elements array
|
42
|
+
assert @ordered_set.elements.include?(@item_1)
|
43
|
+
assert @ordered_set.elements.include?(@item_2)
|
44
|
+
assert @ordered_set.elements.include?(@item_3)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_at
|
48
|
+
# add items to container
|
49
|
+
@ordered_set.add @item_1
|
50
|
+
@ordered_set.add @item_2
|
51
|
+
@ordered_set.add @item_3
|
52
|
+
|
53
|
+
# check if all items are inserted
|
54
|
+
assert_equal 3, @ordered_set.elements.size
|
55
|
+
|
56
|
+
# check item for each position
|
57
|
+
assert_equal @item_1.uri, @ordered_set.at(1).uri
|
58
|
+
assert_equal @item_2.uri, @ordered_set.at(2).uri
|
59
|
+
assert_equal @item_3.uri, @ordered_set.at(3).uri
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_order
|
63
|
+
# add items to container
|
64
|
+
@ordered_set.add @item_1
|
65
|
+
@ordered_set.add @item_2
|
66
|
+
@ordered_set.add @item_3
|
67
|
+
|
68
|
+
# check if container include each item
|
69
|
+
assert_equal @ordered_set.elements[0].uri, @item_1.uri
|
70
|
+
assert_equal @ordered_set.elements[1].uri, @item_2.uri
|
71
|
+
assert_equal @ordered_set.elements[2].uri, @item_3.uri
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_delete
|
75
|
+
# add items to container
|
76
|
+
@ordered_set.add @item_1
|
77
|
+
@ordered_set.add @item_2
|
78
|
+
@ordered_set.add @item_3
|
79
|
+
|
80
|
+
# check item number
|
81
|
+
assert_equal 3, @ordered_set.elements.size
|
82
|
+
|
83
|
+
# delete item 2
|
84
|
+
@ordered_set.delete(2)
|
85
|
+
assert_equal 2, @ordered_set.elements.size
|
86
|
+
assert_equal @ordered_set.elements[0].uri, @item_1.uri
|
87
|
+
assert_equal @ordered_set.elements[1].uri, @item_3.uri
|
88
|
+
|
89
|
+
# delete all items
|
90
|
+
@ordered_set.delete_all
|
91
|
+
assert_equal 0, @ordered_set.elements.size
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_replace
|
95
|
+
# add items to container
|
96
|
+
@ordered_set.add @item_1
|
97
|
+
@ordered_set.add @item_2
|
98
|
+
|
99
|
+
assert_equal 2, @ordered_set.elements.size
|
100
|
+
|
101
|
+
# replace item 2
|
102
|
+
@ordered_set.replace(2, @item_3)
|
103
|
+
|
104
|
+
# check if item 2 is replaced
|
105
|
+
assert_equal 2, @ordered_set.elements.size
|
106
|
+
assert_equal @ordered_set.elements[0].uri, @item_1.uri
|
107
|
+
assert_equal @ordered_set.elements[1].uri, @item_3.uri
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
# Author:: Eyal Oren
|
2
|
+
# Copyright:: (c) 2005-2006
|
3
|
+
# License:: LGPL
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
require 'active_rdf'
|
7
|
+
require 'federation/connection_pool'
|
8
|
+
require "#{File.dirname(__FILE__)}/../common"
|
9
|
+
|
10
|
+
class TestResourceReading < Test::Unit::TestCase
|
11
|
+
def setup
|
12
|
+
ConnectionPool.clear
|
13
|
+
@adapter = get_adapter
|
14
|
+
@adapter.load "#{File.dirname(__FILE__)}/../test_person_data.nt"
|
15
|
+
Namespace.register(:test, 'http://activerdf.org/test/')
|
16
|
+
|
17
|
+
@eyal = RDFS::Resource.new 'http://activerdf.org/test/eyal'
|
18
|
+
end
|
19
|
+
|
20
|
+
def teardown
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_find_all_instances
|
24
|
+
assert_equal 7, RDFS::Resource.find_all.size
|
25
|
+
assert_equal [TEST::eyal, TEST::other], TEST::Person.find_all
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_class_predicates
|
29
|
+
assert_equal 5, RDFS::Resource.predicates.size
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_eyal_predicates
|
33
|
+
# assert that eyal's three direct predicates are eye, age, and type
|
34
|
+
preds = @eyal.direct_predicates.collect {|p| p.uri }
|
35
|
+
assert_equal 3, preds.size
|
36
|
+
['age', 'eye', 'type'].each do |pr|
|
37
|
+
assert preds.any? {|uri| uri =~ /.*#{pr}$/ }, "Eyal should have predicate #{pr}"
|
38
|
+
end
|
39
|
+
|
40
|
+
# test class level predicates
|
41
|
+
class_preds = @eyal.class_level_predicates.collect {|p| p.uri }
|
42
|
+
# eyal.type: person and resource, has predicates age, eye
|
43
|
+
# not default rdfs:label, rdfs:comment, etc. because not using rdfs reasoning
|
44
|
+
assert_equal 5, class_preds.size
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_eyal_types
|
48
|
+
types = @eyal.type
|
49
|
+
assert_equal 2, types.size
|
50
|
+
assert types.include?(TEST::Person)
|
51
|
+
assert types.include?(RDFS::Resource)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_eyal_age
|
55
|
+
# triple exists '<eyal> age 27'
|
56
|
+
assert_equal 27, @eyal.age
|
57
|
+
assert_equal 27, @eyal.test::age
|
58
|
+
assert_equal [27], @eyal.all_age
|
59
|
+
|
60
|
+
# Person has property car, but eyal has no value for it
|
61
|
+
assert_equal nil, @eyal.car
|
62
|
+
assert_equal nil, @eyal.test::car
|
63
|
+
assert_equal [], @eyal.all_test::car
|
64
|
+
|
65
|
+
# non-existent method should throw error
|
66
|
+
assert_equal nil, @eyal.non_existing_method
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_eyal_type
|
70
|
+
assert_instance_of RDFS::Resource, @eyal
|
71
|
+
assert_instance_of TEST::Person, @eyal
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_find_options
|
75
|
+
all = [Namespace.lookup(:test,:Person), Namespace.lookup(:rdfs, :Class), Namespace.lookup(:rdf, :Property), @eyal, TEST::car, TEST::age, TEST::eye]
|
76
|
+
found = RDFS::Resource.find
|
77
|
+
assert_equal all.sort, found.sort
|
78
|
+
|
79
|
+
properties = [TEST::car, TEST::age, TEST::eye]
|
80
|
+
found = RDFS::Resource.find(:where => {RDFS::domain => RDFS::Resource})
|
81
|
+
assert_equal properties.sort, found.sort
|
82
|
+
|
83
|
+
found = RDFS::Resource.find(:where => {RDFS::domain => RDFS::Resource, :prop => :any})
|
84
|
+
assert_equal properties.sort, found.sort
|
85
|
+
|
86
|
+
found = TEST::Person.find(:order => TEST::age)
|
87
|
+
assert_equal [TEST::other, TEST::eyal].sort, found.sort
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_find_methods
|
91
|
+
assert_equal [@eyal], RDFS::Resource.find_by_eye('blue')
|
92
|
+
assert_equal [@eyal], RDFS::Resource.find_by_test::eye('blue')
|
93
|
+
|
94
|
+
assert_equal [@eyal], RDFS::Resource.find_by_age(27)
|
95
|
+
assert_equal [@eyal], RDFS::Resource.find_by_test::age(27)
|
96
|
+
|
97
|
+
assert_equal [@eyal], RDFS::Resource.find_by_age_and_eye(27, 'blue')
|
98
|
+
assert_equal [@eyal], RDFS::Resource.find_by_test::age_and_test::eye(27, 'blue')
|
99
|
+
assert_equal [@eyal], RDFS::Resource.find_by_test::age_and_eye(27, 'blue')
|
100
|
+
assert_equal [@eyal], RDFS::Resource.find_by_age_and_test::eye(27, 'blue')
|
101
|
+
end
|
102
|
+
|
103
|
+
# test for writing if no write adapter is defined (like only sparqls)
|
104
|
+
def test_write_without_write_adapter
|
105
|
+
ConnectionPool.clear
|
106
|
+
get_read_only_adapter
|
107
|
+
assert_raises(ActiveRdfError) { @eyal.test::age = 18 }
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_finders_with_options
|
111
|
+
ConnectionPool.clear
|
112
|
+
adapter = get_adapter
|
113
|
+
file_one = "#{File.dirname(__FILE__)}/../small-one.nt"
|
114
|
+
file_two = "#{File.dirname(__FILE__)}/../small-two.nt"
|
115
|
+
one = RDFS::Resource.new("file:#{file_one}")
|
116
|
+
two = RDFS::Resource.new("file:#{file_two}")
|
117
|
+
|
118
|
+
if (adapter.class.to_s != "SesameAdapter")
|
119
|
+
adapter.load file_one
|
120
|
+
adapter.load file_two
|
121
|
+
else
|
122
|
+
adapter.load(file_one, 'ntriples', one)
|
123
|
+
adapter.load(file_two, 'ntriples', two)
|
124
|
+
end
|
125
|
+
|
126
|
+
assert_equal 2, RDFS::Resource.find.size
|
127
|
+
assert_equal 2, RDFS::Resource.find(:all).size
|
128
|
+
assert_equal 2, RDFS::Resource.find(:all, :limit => 10).size
|
129
|
+
assert_equal 1, RDFS::Resource.find(:all, :limit => 1).size
|
130
|
+
assert_equal 1, RDFS::Resource.find(:all, :context => one).size
|
131
|
+
assert_equal 1, RDFS::Resource.find(:all, :context => one, :limit => 1).size
|
132
|
+
assert_equal 0, RDFS::Resource.find(:all, :context => one, :limit => 0).size
|
133
|
+
|
134
|
+
assert_equal 1, RDFS::Resource.find_by_eye('blue').size
|
135
|
+
assert_equal 1, RDFS::Resource.find_by_eye('blue', :context => one).size
|
136
|
+
assert_equal 0, RDFS::Resource.find_by_eye('blue', :context => two).size
|
137
|
+
|
138
|
+
assert_equal 2, RDFS::Resource.find_by_rdf::type(RDFS::Resource).size
|
139
|
+
assert_equal 1, RDFS::Resource.find_by_rdf::type(RDFS::Resource, :context => one).size
|
140
|
+
assert_equal 1, RDFS::Resource.find_by_eye_and_rdf::type('blue', RDFS::Resource, :context => one).size
|
141
|
+
end
|
142
|
+
|
143
|
+
def test_reading_with_block
|
144
|
+
qs=<<EOF
|
145
|
+
SELECT DISTINCT ?o WHERE { <http://activerdf.org/test/eyal>
|
146
|
+
<http://activerdf.org/test/age> ?o . FILTER (regex(lang(?o), '^nl$'))}
|
147
|
+
EOF
|
148
|
+
@eyal.age {|query, obj| query.lang(obj, "nl"); assert_equal qs.gsub("\n",'').strip, query.to_sp.strip}
|
149
|
+
end
|
150
|
+
end
|