activerdf_net7 1.6.16 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/CHANGELOG +63 -0
  2. data/activerdf-jena/lib/activerdf_jena/jena.rb +4 -4
  3. data/activerdf-jena/lib/activerdf_jena/jena_adapter.rb +55 -55
  4. data/activerdf-jena/lib/activerdf_jena/lucene.rb +1 -1
  5. data/activerdf-jena/lib/activerdf_jena/ng4j.rb +7 -7
  6. data/activerdf-jena/lib/activerdf_jena/ng4j_adapter.rb +47 -47
  7. data/activerdf-jena/lib/activerdf_jena/pellet.rb +1 -1
  8. data/activerdf-jena/test/test_jena_adapter.rb +121 -120
  9. data/activerdf-jena/test/test_ng4j_adapter.rb +111 -110
  10. data/activerdf-rdflite/lib/activerdf_rdflite/fetching.rb +23 -19
  11. data/activerdf-rdflite/lib/activerdf_rdflite/rdflite.rb +153 -277
  12. data/activerdf-rdflite/lib/activerdf_rdflite/suggesting.rb +2 -2
  13. data/activerdf-rdflite/test/test_fetching.rb +7 -22
  14. data/activerdf-rdflite/test/test_rdflite.rb +44 -257
  15. data/activerdf-redland/lib/activerdf_redland/redland.rb +246 -282
  16. data/activerdf-redland/test/test_redland_adapter.rb +62 -224
  17. data/activerdf-sesame/ext/wrapper-sesame2.jar +0 -0
  18. data/activerdf-sesame/java/build.number +2 -2
  19. data/activerdf-sesame/java/build.xml +0 -0
  20. data/activerdf-sesame/java/lib/junit-3.8.2.jar +0 -0
  21. data/activerdf-sesame/java/settings.xml +0 -0
  22. data/activerdf-sesame/java/src/org/activerdf/wrapper/sesame2/WrapperForSesame2.java +0 -0
  23. data/activerdf-sesame/java/temp/build/org/activerdf/wrapper/sesame2/WrapperForSesame2.class +0 -0
  24. data/activerdf-sesame/java/temp/manifest/MANIFEST.MF +2 -2
  25. data/activerdf-sesame/java/test-src/org/activerdf/wrapper/sesame2/TestWrapperForSesame2.java +0 -0
  26. data/activerdf-sesame/lib/activerdf_sesame/sesame.rb +360 -364
  27. data/activerdf-sesame/test/test_sesame_adapter.rb +85 -83
  28. data/activerdf-sparql/lib/activerdf_sparql/sparql.rb +147 -148
  29. data/activerdf-sparql/lib/activerdf_sparql/sparql_result_parser.rb +5 -5
  30. data/activerdf-sparql/test/test_sparql_adapter.rb +2 -0
  31. data/activerdf-yars/lib/activerdf_yars/jars2.rb +85 -83
  32. data/lib/active_rdf/federation/active_rdf_adapter.rb +26 -39
  33. data/lib/active_rdf/federation/connection_pool.rb +119 -110
  34. data/lib/active_rdf/federation/federation_manager.rb +51 -51
  35. data/lib/active_rdf/objectmanager/bnode.rb +8 -2
  36. data/lib/active_rdf/objectmanager/literal.rb +81 -50
  37. data/lib/active_rdf/objectmanager/namespace.rb +117 -84
  38. data/lib/active_rdf/objectmanager/object_manager.rb +101 -96
  39. data/lib/active_rdf/objectmanager/ordered_set.rb +1 -1
  40. data/lib/active_rdf/objectmanager/property.rb +345 -0
  41. data/lib/active_rdf/objectmanager/property_list.rb +4 -4
  42. data/lib/active_rdf/objectmanager/property_lookup.rb +57 -0
  43. data/lib/active_rdf/objectmanager/resource.rb +293 -501
  44. data/lib/active_rdf/objectmanager/resource_like.rb +2 -2
  45. data/lib/active_rdf/objectmanager/resource_query.rb +85 -0
  46. data/lib/active_rdf/queryengine/ntriples_parser.rb +75 -68
  47. data/lib/active_rdf/queryengine/query.rb +237 -183
  48. data/lib/active_rdf/queryengine/query2jars2.rb +17 -15
  49. data/lib/active_rdf/queryengine/query2sparql.rb +107 -101
  50. data/lib/active_rdf.rb +28 -17
  51. data/lib/active_rdf_helpers.rb +37 -5
  52. data/lib/active_rdf_log.rb +11 -11
  53. data/test/adapters/test_activerdf_adapter.rb +138 -0
  54. data/test/{test_adapters.rb → adapters/test_adapters.rb} +6 -24
  55. data/test/adapters/test_bnode_capable_adapter.rb +31 -0
  56. data/test/adapters/test_context_aware_adapter.rb +31 -0
  57. data/test/adapters/test_network_aware_adapter.rb +29 -0
  58. data/test/adapters/test_persistent_adapter.rb +21 -0
  59. data/test/adapters/test_read_only_adapter.rb +15 -0
  60. data/test/adapters/test_reasoning_adapter.rb +11 -0
  61. data/test/adapters/test_writable_adapter.rb +163 -0
  62. data/test/common.rb +78 -96
  63. data/test/federation/test_connection_pool.rb +25 -44
  64. data/test/federation/test_federation_manager.rb +45 -45
  65. data/test/objectmanager/test_literal.rb +47 -26
  66. data/test/objectmanager/test_namespace.rb +3 -1
  67. data/test/objectmanager/test_object_manager.rb +35 -45
  68. data/test/objectmanager/test_ordered_set.rb +1 -1
  69. data/test/objectmanager/test_property.rb +261 -0
  70. data/test/objectmanager/test_resource_reading.rb +196 -104
  71. data/test/objectmanager/test_resource_reasoning.rb +26 -0
  72. data/test/objectmanager/test_resource_writing.rb +34 -25
  73. data/test/queryengine/my_external_resource.rb +5 -1
  74. data/test/queryengine/test_external_resource_class.rb +1 -8
  75. data/test/queryengine/test_ntriples_parser.rb +5 -3
  76. data/test/queryengine/test_query.rb +3 -3
  77. data/test/queryengine/test_query2jars2.rb +2 -2
  78. data/test/queryengine/test_query2sparql.rb +2 -2
  79. data/test/queryengine/test_query_engine.rb +46 -28
  80. metadata +16 -8
  81. data/activerdf-rdflite/test/test_bnode_data.nt +0 -5
  82. data/activerdf-rdflite/test/test_data.nt +0 -32
  83. data/activerdf-rdflite/test/test_escaped_data.nt +0 -2
  84. data/activerdf-redland/test/test_person_data.nt +0 -42
  85. data/test/objectmanager/test_talia_syntax.rb +0 -68
@@ -1,4 +1,4 @@
1
- module RDFS
1
+ module ActiveRDF
2
2
 
3
3
  # Helper Module that contains same additional methods that
4
4
  # are expected from classes that want to behave like
@@ -19,7 +19,7 @@ module RDFS
19
19
  end
20
20
 
21
21
  # NTriple representation of element
22
- def to_ntriple
22
+ def to_literal_s
23
23
  "<#{uri}>"
24
24
  end
25
25
 
@@ -0,0 +1,85 @@
1
+ module ActiveRDF
2
+ # Search for resources of a given type, with given property restrictions.
3
+ # Usage:
4
+ # ResourceQuery.new(TEST::Person).execute # find all TEST::Person resources
5
+ # ResourceQuery.new(TEST::Person).age.execute # find TEST::Person resources that have the property age
6
+ # ResourceQuery.new(TEST::Person).age(27).execute # find TEST::Person resources with property matching the supplied value
7
+ # ResourceQuery.new(TEST::Person).age(27,:context => context_resource).execute # find TEST::Person resources with property matching supplied value and context
8
+ # ResourceQuery.new(TEST::Person).email('personal@email','work@email').execute # find TEST::Person resources with property matching the supplied values
9
+ # ResourceQuery.new(TEST::Person).email(['personal@email','work@email']).execute # find TEST::Person resources with property matching the supplied values
10
+ # ResourceQuery.new(TEST::Person).eye('blue').execute(:all_types => true) # find TEST::Person resources with property matching the supplied value ignoring lang/datatypes
11
+ # ResourceQuery.new(TEST::Person).eye(LocalizedString('blue','en')).execute # find TEST::Person resources with property matching the supplied value
12
+ # ResourceQuery.new(TEST::Person).eye(:regex => /lu/).execute # find TEST::Person resources with property matching the specified regex
13
+ # ResourceQuery.new(TEST::Person).eye(:lang => '@en').execute # find TEST::Person resources with property having the specified language
14
+ # ResourceQuery.new(TEST::Person).age(:datatype => XSD::Integer).execute # find TEST::Person resources with property having the specified datatype
15
+ # ResourceQuery.new(RDFS::Resource).test::age(27).execute # find RDFS::Resources having the fully qualified property and value
16
+ # ResourceQuery.new(TEST::Person).age(27).eye(LocalizedString('blue','en')).execute # chain multiple properties together, ANDing restrictions
17
+ class ResourceQuery
18
+ private(:type)
19
+
20
+ def initialize(type,context = nil)
21
+ @ns = nil
22
+ @type = type
23
+ @query = Query.new.distinct(:s).where(:s,RDF::type,@type,context)
24
+ @var_idx = -1
25
+ end
26
+
27
+ def execute(options = {}, &blk)
28
+ if truefalse(options[:all_types])
29
+ if @query.filter_clauses.values.any?{|operator,operand| operator == :lang or operator == :datatype}
30
+ raise ActiveRdfError, "all_types may not be specified in conjunction with any lang or datatype restrictions"
31
+ end
32
+ @query = @query.dup.all_types
33
+ end
34
+ @query.execute(options, &blk)
35
+ end
36
+
37
+ def method_missing(ns_or_property, *values)
38
+ # if the namespace has been seen, lookup the property
39
+ if !@ns and Namespace.include?(ns_or_property)
40
+ @ns = ns_or_property
41
+ return self
42
+ end
43
+
44
+ property_name = ns_or_property.to_s
45
+ property =
46
+ if @ns
47
+ Namespace.lookup(@ns, property_name)
48
+ else
49
+ @type.instance_predicates.find{|prop| Namespace.localname(prop) == property_name}
50
+ end
51
+ raise ActiveRdfError, "no suitable predicate matching '#{property_name}' found. Maybe you are missing some schema information?" unless property
52
+ @ns = nil
53
+
54
+ # restrict by values if provided
55
+ options = values.extract_options!
56
+ values.flatten!
57
+ if values.size > 0 then values.each do |value|
58
+ @query.where(:s,property,value,options[:context])
59
+ end
60
+ # otherwise restrict by property occurance only
61
+ else
62
+ var = "rq#{@var_idx += 1}".to_sym
63
+ @query.where(:s,property,var,options[:context])
64
+
65
+ # add filters
66
+ if options[:lang] && options[:datatype]
67
+ raise ActiveRdfError, "only lang or datatype may be specified, not both"
68
+ elsif options[:lang]
69
+ @query.lang(var,options[:lang])
70
+ elsif options[:datatype]
71
+ @query.datatype(var,options[:datatype])
72
+ end
73
+ if options[:regex]
74
+ @query.regex(var,options[:regex])
75
+ end
76
+ end
77
+
78
+ self
79
+ end
80
+
81
+ def to_s
82
+ @query.to_s
83
+ end
84
+ end
85
+ end
@@ -5,86 +5,93 @@
5
5
  require 'uuidtools'
6
6
  require 'strscan'
7
7
 
8
- # ntriples parser
9
- class NTriplesParser
8
+ module ActiveRDF
9
+ # ntriples parser
10
+ class NTriplesParser
10
11
  def self.parse_node(input, resource_class = RDFS::Resource)
11
- case input
12
- when MatchBNode
13
- resource_class.new("http://www.activerdf.org/bnode/#{UUID.random_create}/#$1")
14
- when MatchLiteral
15
- value = fix_unicode($1)
16
- if $2
17
- Literal.typed(value, resource_class.new($2))
18
- else
19
- value
20
- end
21
- when MatchResource
22
- resource_class.new($1)
23
- else
24
- nil
25
- end
26
- end
27
-
28
- # parses an input string of ntriples and returns a nested array of [s, p, o]
29
- # (which are in turn ActiveRDF objects)
30
- def self.parse(input)
31
- # need unique identifier for this batch of triples (to detect occurence of
32
- # same bnodes _:#1
33
- uuid = UUID.random_create.to_s
34
-
35
- input.collect do |triple|
36
- nodes = []
37
- scanner = StringScanner.new(triple)
38
- scanner.skip(/\s+/)
39
- while not scanner.eos?
40
- nodes << scanner.scan(MatchNode)
41
- scanner.skip(/\s+/)
42
- scanner.terminate if nodes.size == 3
43
- end
44
-
45
- # handle bnodes if necessary (bnodes need to have uri generated)
46
- subject = case nodes[0]
12
+ case input
47
13
  when MatchBNode
48
- RDFS::Resource.new("http://www.activerdf.org/bnode/#{uuid}/#$1")
49
- when MatchResource
50
- RDFS::Resource.new($1)
51
- end
52
-
53
- predicate = case nodes[1]
54
- when MatchResource
55
- RDFS::Resource.new($1)
56
- end
57
-
58
- # handle bnodes and literals if necessary (literals need unicode fixing)
59
- object = case nodes[2]
60
- when MatchBNode
61
- RDFS::Resource.new("http://www.activerdf.org/bnode/#{uuid}/#$1")
14
+ resource_class.new("http://www.activerdf.org/bnode/#{UUIDTools::UUID.random_create}/#$1")
62
15
  when MatchLiteral
63
16
  value = fix_unicode($1)
64
17
  if $2
65
- Literal.typed(value, RDFS::Resource.new($2))
18
+ RDFS::Literal.typed(value, resource_class.new($2))
19
+ elsif $3
20
+ LocalizedString.new(value,$3)
66
21
  else
67
22
  value
68
23
  end
69
24
  when MatchResource
70
- RDFS::Resource.new($1)
25
+ resource_class.new($1)
26
+ else
27
+ nil
71
28
  end
29
+ end
30
+
31
+ # parses an input string of ntriples and returns a nested array of [s, p, o]
32
+ # (which are in turn ActiveRDF objects)
33
+ def self.parse(input, result_type = RDFS::Resource)
34
+ # need unique identifier for this batch of triples (to detect occurence of
35
+ # same bnodes _:#1
36
+ uuid = UUIDTools::UUID.random_create.to_s
37
+
38
+ input.split(/\r|\n/).collect do |triple|
39
+ next if triple =~ /^\s*#|^\s*$/
40
+ nodes = []
41
+ scanner = StringScanner.new(triple)
42
+ scanner.skip(/\s+/)
43
+ while not scanner.eos?
44
+ nodes << scanner.scan(MatchNode)
45
+ scanner.skip(/\s+/)
46
+ scanner.terminate if nodes.size == 3
47
+ end
48
+
49
+ # handle bnodes if necessary (bnodes need to have uri generated)
50
+ subject = case nodes[0]
51
+ when MatchBNode
52
+ result_type.new("http://www.activerdf.org/bnode/#{uuid}/#$1")
53
+ when MatchResource
54
+ result_type.new($1)
55
+ end
56
+
57
+ predicate = case nodes[1]
58
+ when MatchResource
59
+ result_type.new($1)
60
+ end
72
61
 
73
- # collect s, p, o into array to be returned
74
- [subject, predicate, object]
62
+ # handle bnodes and literals if necessary (literals need unicode fixing)
63
+ object = case nodes[2]
64
+ when MatchBNode
65
+ result_type.new("http://www.activerdf.org/bnode/#{uuid}/#$1")
66
+ when MatchLiteral
67
+ value = fix_unicode($1)
68
+ if $2
69
+ RDFS::Literal.typed(value, result_type.new($2))
70
+ elsif $3
71
+ LocalizedString.new(value, $3)
72
+ else
73
+ value
74
+ end
75
+ when MatchResource
76
+ result_type.new($1)
77
+ end
78
+
79
+ # collect s, p, o into array to be returned
80
+ [subject, predicate, object]
81
+ end.compact
75
82
  end
76
- end
77
83
 
78
- private
79
- # constants for extracting resources/literals from sql results
80
- MatchNode = Regexp.union(/"(?:\\"|[^"])*"(?:\^\^\S+)?/,/_:\S*/,/<[^>]*>/)
81
- MatchBNode = /_:(\S*)/
82
- MatchResource = /<([^>]*)>/
83
- MatchLiteral = /"((?:\\"|[^"])*)"(?:\^\^<(\S+)>)?/
84
+ private
85
+ # constants for extracting resources/literals from sql results
86
+ MatchBNode = /_:(\S*)/
87
+ MatchResource = /<([^>]*)>/
88
+ MatchLiteral = /"((?:\\"|[^"])*)"(?:\^\^<(\S+)>|@(\S+))?/
89
+ MatchNode = Regexp.union(MatchBNode,MatchResource,MatchLiteral)
84
90
 
85
- # fixes unicode characters in literals (because we parse them wrongly somehow)
86
- def self.fix_unicode(str)
87
- tmp = str.gsub(/\\\u([0-9a-fA-F]{4,4})/u){ "U+#$1" }
88
- tmp.gsub(/U\+([0-9a-fA-F]{4,4})/u){["#$1".hex ].pack('U*')}
91
+ # fixes unicode characters in literals (because we parse them wrongly somehow)
92
+ def self.fix_unicode(str)
93
+ tmp = str.gsub(/\\\u([0-9a-fA-F]{4,4})/u){ "U+#$1" }
94
+ tmp.gsub(/U\+([0-9a-fA-F]{4,4})/u){["#$1".hex ].pack('U*')}
95
+ end
89
96
  end
90
- end
97
+ end