rdf-virtuoso 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rdf/virtuoso/query.rb +69 -33
- data/lib/rdf/virtuoso/version.rb +1 -1
- data/spec/query_spec.rb +27 -7
- data/spec/spec_helper.rb +1 -10
- metadata +10 -10
    
        data/lib/rdf/virtuoso/query.rb
    CHANGED
    
    | @@ -266,6 +266,13 @@ module RDF::Virtuoso | |
| 266 266 | 
             
                  self
         | 
| 267 267 | 
             
                end
         | 
| 268 268 |  | 
| 269 | 
            +
                # @param RDF::URI uri
         | 
| 270 | 
            +
                # @return [Query]
         | 
| 271 | 
            +
                def from_named(uri)
         | 
| 272 | 
            +
                  options[:from_named] = uri
         | 
| 273 | 
            +
                  self
         | 
| 274 | 
            +
                end
         | 
| 275 | 
            +
             | 
| 269 276 | 
             
                # @param RDF::URI uri
         | 
| 270 277 | 
             
                # @return [Query]
         | 
| 271 278 | 
             
                def graph(uri)
         | 
| @@ -284,6 +291,25 @@ module RDF::Virtuoso | |
| 284 291 |  | 
| 285 292 | 
             
                alias_method :whether, :where
         | 
| 286 293 |  | 
| 294 | 
            +
                ##
         | 
| 295 | 
            +
                # @param  [Array<RDF::Query::Pattern, Array>] patterns
         | 
| 296 | 
            +
                # @return [Query]
         | 
| 297 | 
            +
                # Group is a non-SPARQL function. It works same as where, but groups the
         | 
| 298 | 
            +
                # patterns within brackets: { }, allowing to structure the query.
         | 
| 299 | 
            +
                def group(*patterns)
         | 
| 300 | 
            +
                  @patterns += [Pattern.new(:start_group_pattern)] + build_patterns(patterns) + [Pattern.new(:end_group_pattern)]
         | 
| 301 | 
            +
                  self
         | 
| 302 | 
            +
                end
         | 
| 303 | 
            +
             | 
| 304 | 
            +
                ##
         | 
| 305 | 
            +
                # @param RDF::URI uri
         | 
| 306 | 
            +
                # @return [Query]
         | 
| 307 | 
            +
                # Inline version of graph
         | 
| 308 | 
            +
                def graph2(uri)
         | 
| 309 | 
            +
                  @patterns += [Pattern.new(:graph_statement, uri)]
         | 
| 310 | 
            +
                  self
         | 
| 311 | 
            +
                end
         | 
| 312 | 
            +
             | 
| 287 313 | 
             
                ##
         | 
| 288 314 | 
             
                # @param  [Array<Symbol, String>] variables
         | 
| 289 315 | 
             
                # @return [Query]
         | 
| @@ -310,7 +336,7 @@ module RDF::Virtuoso | |
| 310 336 | 
             
                  options[:reduced] = state
         | 
| 311 337 | 
             
                  self
         | 
| 312 338 | 
             
                end
         | 
| 313 | 
            -
             | 
| 339 | 
            +
             | 
| 314 340 | 
             
                ## SPARQL 1.1 Aggregates
         | 
| 315 341 | 
             
                # @return [Query]
         | 
| 316 342 | 
             
                # @see    http://www.w3.org/TR/sparql11-query/#defn_aggCount
         | 
| @@ -577,40 +603,42 @@ module RDF::Virtuoso | |
| 577 603 | 
             
                  end
         | 
| 578 604 |  | 
| 579 605 | 
             
                  buffer << "FROM #{serialize_value(options[:from])}" if options[:from]
         | 
| 606 | 
            +
                  buffer << "FROM NAMED #{serialize_value(options[:from_named])}" if options[:from_named]
         | 
| 607 | 
            +
             | 
| 580 608 |  | 
| 581 609 | 
             
                  unless patterns.empty? && ([:describe, :insert_data, :delete_data, :create, :clear, :drop].include?(form))
         | 
| 582 610 | 
             
                    buffer << 'WHERE {'
         | 
| 583 | 
            -
             | 
| 611 | 
            +
             | 
| 584 612 | 
             
                    buffer << '{' if options[:unions]
         | 
| 585 | 
            -
             | 
| 613 | 
            +
             | 
| 586 614 | 
             
                    # iterate patterns
         | 
| 587 615 | 
             
                    # does patterns have :context hash? build with GRAPH statement
         | 
| 588 | 
            -
                     | 
| 589 | 
            -
                       | 
| 590 | 
            -
                        buffer << "GRAPH #{serialize_value(RDF::URI(pattern.context))}" | 
| 616 | 
            +
                    patterns.each do | pattern|
         | 
| 617 | 
            +
                      if pattern.context
         | 
| 618 | 
            +
                        buffer << "GRAPH #{serialize_value(RDF::URI(pattern.context))}"
         | 
| 591 619 | 
             
                        buffer << '{'
         | 
| 592 620 | 
             
                        buffer << serialize_patterns(pattern)
         | 
| 593 621 | 
             
                        buffer << '}'
         | 
| 622 | 
            +
                      else
         | 
| 623 | 
            +
                        buffer << serialize_patterns(pattern)
         | 
| 594 624 | 
             
                      end
         | 
| 595 | 
            -
                    else
         | 
| 596 | 
            -
                      buffer += serialize_patterns(patterns)
         | 
| 597 625 | 
             
                    end
         | 
| 598 | 
            -
             | 
| 626 | 
            +
             | 
| 599 627 | 
             
                    if options[:optionals]
         | 
| 600 628 | 
             
                      options[:optionals].each do |patterns|
         | 
| 601 629 | 
             
                        buffer << 'OPTIONAL {'
         | 
| 602 | 
            -
             | 
| 603 | 
            -
            	         | 
| 604 | 
            -
             | 
| 605 | 
            -
             | 
| 606 | 
            -
             | 
| 607 | 
            -
             | 
| 608 | 
            -
             | 
| 609 | 
            -
             | 
| 610 | 
            -
             | 
| 611 | 
            -
             | 
| 612 | 
            -
             | 
| 613 | 
            -
             | 
| 630 | 
            +
             | 
| 631 | 
            +
            	        patterns.each do | pattern|
         | 
| 632 | 
            +
                      if pattern.context
         | 
| 633 | 
            +
                        buffer << "GRAPH #{serialize_value(RDF::URI(pattern.context))}"
         | 
| 634 | 
            +
                        buffer << '{'
         | 
| 635 | 
            +
                        buffer << serialize_patterns(pattern)
         | 
| 636 | 
            +
                        buffer << '}'
         | 
| 637 | 
            +
                      else
         | 
| 638 | 
            +
                        buffer << serialize_patterns(pattern)
         | 
| 639 | 
            +
                      end
         | 
| 640 | 
            +
                    end
         | 
| 641 | 
            +
             | 
| 614 642 | 
             
                        buffer << '}'
         | 
| 615 643 | 
             
                      end
         | 
| 616 644 | 
             
                    end
         | 
| @@ -619,21 +647,21 @@ module RDF::Virtuoso | |
| 619 647 | 
             
                      options[:minuses].each do |patterns|
         | 
| 620 648 | 
             
                        buffer << 'MINUS {'
         | 
| 621 649 |  | 
| 622 | 
            -
            	         | 
| 623 | 
            -
             | 
| 624 | 
            -
             | 
| 625 | 
            -
             | 
| 626 | 
            -
             | 
| 627 | 
            -
             | 
| 628 | 
            -
             | 
| 629 | 
            -
             | 
| 630 | 
            -
             | 
| 631 | 
            -
             | 
| 650 | 
            +
            	        patterns.each do | pattern|
         | 
| 651 | 
            +
                      if pattern.context
         | 
| 652 | 
            +
                        buffer << "GRAPH #{serialize_value(RDF::URI(pattern.context))}"
         | 
| 653 | 
            +
                        buffer << '{'
         | 
| 654 | 
            +
                        buffer << serialize_patterns(pattern)
         | 
| 655 | 
            +
                        buffer << '}'
         | 
| 656 | 
            +
                      else
         | 
| 657 | 
            +
                        buffer << serialize_patterns(pattern)
         | 
| 658 | 
            +
                      end
         | 
| 659 | 
            +
                    end
         | 
| 632 660 |  | 
| 633 661 | 
             
                        buffer << '}'
         | 
| 634 662 | 
             
                      end
         | 
| 635 663 | 
             
                    end
         | 
| 636 | 
            -
             | 
| 664 | 
            +
             | 
| 637 665 | 
             
                    if options[:filters]
         | 
| 638 666 | 
             
                      buffer += options[:filters].map { |filter| "FILTER(#{filter})" }
         | 
| 639 667 | 
             
                    end
         | 
| @@ -666,7 +694,15 @@ module RDF::Virtuoso | |
| 666 694 | 
             
                # @private
         | 
| 667 695 | 
             
                def serialize_patterns(patterns)
         | 
| 668 696 | 
             
                  if patterns.is_a?(RDF::Query::Pattern)
         | 
| 669 | 
            -
                    patterns. | 
| 697 | 
            +
                    if patterns.variables[:start_group_pattern]
         | 
| 698 | 
            +
                      "{"
         | 
| 699 | 
            +
                    elsif patterns.variables[:end_group_pattern]
         | 
| 700 | 
            +
                      "}"
         | 
| 701 | 
            +
                    elsif patterns.variables[:graph_statement]
         | 
| 702 | 
            +
                      "GRAPH #{serialize_value(patterns[1])}"
         | 
| 703 | 
            +
                    else
         | 
| 704 | 
            +
                      patterns.to_triple.map { |v| serialize_value(v) }.join(' ') << " ."
         | 
| 705 | 
            +
                    end
         | 
| 670 706 | 
             
                  else
         | 
| 671 707 | 
             
                    patterns.map do |p|
         | 
| 672 708 | 
             
                      p.to_triple.map { |v| serialize_value(v) }.join(' ') << " ."
         | 
    
        data/lib/rdf/virtuoso/version.rb
    CHANGED
    
    
    
        data/spec/query_spec.rb
    CHANGED
    
    | @@ -126,26 +126,34 @@ describe RDF::Virtuoso::Query do | |
| 126 126 | 
             
                  @query.select(:s, :p, :o).where([:s, :p, :o]).to_s.should == "SELECT ?s ?p ?o WHERE { ?s ?p ?o . }"
         | 
| 127 127 | 
             
                end
         | 
| 128 128 |  | 
| 129 | 
            -
                it "should support SELECT  | 
| 129 | 
            +
                it "should support SELECT FROM" do
         | 
| 130 130 | 
             
                  @graph = RDF::URI("http://example.org/")
         | 
| 131 131 | 
             
                  @query.select(:s).where([:s, :p, :o]).from(@graph).to_s.should == "SELECT ?s FROM <#{@graph}> WHERE { ?s ?p ?o . }"
         | 
| 132 132 | 
             
                end
         | 
| 133 | 
            -
             | 
| 133 | 
            +
             | 
| 134 | 
            +
                it "should support SELECT FROM and FROM NAMED" do
         | 
| 135 | 
            +
                  @graph1 = RDF::URI("a")
         | 
| 136 | 
            +
                  @graph2 = RDF::URI("b")
         | 
| 137 | 
            +
                  @query.select(:s).where([:s, :p, :o, :context => @graph2]).from(@graph1).from_named(@graph2).to_s.should ==
         | 
| 138 | 
            +
                    "SELECT ?s FROM <#{@graph1}> FROM NAMED <#{@graph2}> WHERE { GRAPH <#{@graph2}> { ?s ?p ?o . } }"
         | 
| 139 | 
            +
                end
         | 
| 140 | 
            +
             | 
| 141 | 
            +
             | 
| 134 142 | 
             
                it "should support SELECT with complex WHERE patterns" do
         | 
| 135 143 | 
             
                  @query.select.where(
         | 
| 136 | 
            -
                  [:s, :p, :o], | 
| 144 | 
            +
                  [:s, :p, :o],
         | 
| 137 145 | 
             
                  [:s, RDF.type, RDF::DC.Document]
         | 
| 138 | 
            -
                  ).to_s.should == | 
| 146 | 
            +
                  ).to_s.should ==
         | 
| 139 147 | 
             
                    "SELECT * WHERE { ?s ?p ?o . ?s <#{RDF.type}> <#{RDF::DC.Document}> . }"
         | 
| 140 148 | 
             
                end
         | 
| 141 149 |  | 
| 142 150 | 
             
                it "should support SELECT WHERE patterns from different GRAPH contexts" do
         | 
| 143 151 | 
             
                  @graph1 = "http://example1.org/"
         | 
| 144 152 | 
             
                  @graph2 = "http://example2.org/"
         | 
| 145 | 
            -
                  @query.select.where([:s, :p, :o, :context => @graph1],[:s, RDF.type, RDF::DC.Document, :context => @graph2]).to_s.should == | 
| 153 | 
            +
                  @query.select.where([:s, :p, :o, :context => @graph1],[:s, RDF.type, RDF::DC.Document, :context => @graph2]).to_s.should ==
         | 
| 146 154 | 
             
                    "SELECT * WHERE { GRAPH <#{@graph1}> { ?s ?p ?o . } GRAPH <#{@graph2}> { ?s <#{RDF.type}> <#{RDF::DC.Document}> . } }"
         | 
| 147 155 | 
             
                end
         | 
| 148 | 
            -
             | 
| 156 | 
            +
             | 
| 149 157 | 
             
                it "should support string objects in SPARQL queries" do
         | 
| 150 158 | 
             
                  @query.select.where([:s, :p, "dummyobject"]).to_s.should == "SELECT * WHERE { ?s ?p \"dummyobject\" . }"
         | 
| 151 159 | 
             
                end
         | 
| @@ -322,7 +330,19 @@ describe RDF::Virtuoso::Query do | |
| 322 330 | 
             
                  @query.select.where([:s, RDF::DC.abstract, :o]).define(define).to_s.should ==
         | 
| 323 331 | 
             
                  "DEFINE #{define} SELECT * WHERE { ?s <#{RDF::DC.abstract}> ?o . }"
         | 
| 324 332 | 
             
                end
         | 
| 325 | 
            -
             | 
| 333 | 
            +
             | 
| 334 | 
            +
                it "should support grouping graph patterns within brackets" do
         | 
| 335 | 
            +
                  @query.select.where.group([:s, :p, :o],[:s2, :p2, :o2]).
         | 
| 336 | 
            +
                    where([:s3, :p3, :o3]).to_s.should ==
         | 
| 337 | 
            +
                  "SELECT * WHERE { { ?s ?p ?o . ?s2 ?p2 ?o2 . } ?s3 ?p3 ?o3 . }"
         | 
| 338 | 
            +
                end
         | 
| 339 | 
            +
             | 
| 340 | 
            +
                it "should support grouping with several graph statements" do
         | 
| 341 | 
            +
                  @query.select.where.graph2(RDF::URI.new("a")).group([:s, :p, :o],[:s2, :p2, :o2]).
         | 
| 342 | 
            +
                    where.graph2(RDF::URI.new("b")).group([:s3, :p3, :o3]).to_s.should ==
         | 
| 343 | 
            +
                    "SELECT * WHERE { GRAPH <a> { ?s ?p ?o . ?s2 ?p2 ?o2 . } GRAPH <b> { ?s3 ?p3 ?o3 . } }"
         | 
| 344 | 
            +
                end
         | 
| 345 | 
            +
             | 
| 326 346 | 
             
              end
         | 
| 327 347 |  | 
| 328 348 | 
             
              context "when building DESCRIBE queries" do
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | @@ -1,12 +1,3 @@ | |
| 1 1 | 
             
            require 'rdf/spec'
         | 
| 2 2 | 
             
            require 'rdf'
         | 
| 3 | 
            -
            require 'rdf/virtuoso'
         | 
| 4 | 
            -
            #require 'active_rdf'
         | 
| 5 | 
            -
            require 'vcr'
         | 
| 6 | 
            -
             | 
| 7 | 
            -
            VCR.configure do |c|
         | 
| 8 | 
            -
              c.cassette_library_dir = 'fixtures/cassettes'
         | 
| 9 | 
            -
              c.hook_into :webmock
         | 
| 10 | 
            -
            end
         | 
| 11 | 
            -
             | 
| 12 | 
            -
            Dir[File.expand_path('../../spec/support/**/*.rb', File.path(__FILE__))].each { |f| require f }
         | 
| 3 | 
            +
            require 'rdf/virtuoso'
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: rdf-virtuoso
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.2
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -10,7 +10,7 @@ authors: | |
| 10 10 | 
             
            autorequire: 
         | 
| 11 11 | 
             
            bindir: bin
         | 
| 12 12 | 
             
            cert_chain: []
         | 
| 13 | 
            -
            date:  | 
| 13 | 
            +
            date: 2013-03-04 00:00:00.000000000 Z
         | 
| 14 14 | 
             
            dependencies:
         | 
| 15 15 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 16 16 | 
             
              name: rspec
         | 
| @@ -19,7 +19,7 @@ dependencies: | |
| 19 19 | 
             
                requirements:
         | 
| 20 20 | 
             
                - - ~>
         | 
| 21 21 | 
             
                  - !ruby/object:Gem::Version
         | 
| 22 | 
            -
                    version: 2. | 
| 22 | 
            +
                    version: 2.13.0
         | 
| 23 23 | 
             
              type: :development
         | 
| 24 24 | 
             
              prerelease: false
         | 
| 25 25 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| @@ -27,7 +27,7 @@ dependencies: | |
| 27 27 | 
             
                requirements:
         | 
| 28 28 | 
             
                - - ~>
         | 
| 29 29 | 
             
                  - !ruby/object:Gem::Version
         | 
| 30 | 
            -
                    version: 2. | 
| 30 | 
            +
                    version: 2.13.0
         | 
| 31 31 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 32 32 | 
             
              name: rdf-spec
         | 
| 33 33 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -35,7 +35,7 @@ dependencies: | |
| 35 35 | 
             
                requirements:
         | 
| 36 36 | 
             
                - - ~>
         | 
| 37 37 | 
             
                  - !ruby/object:Gem::Version
         | 
| 38 | 
            -
                    version: 0. | 
| 38 | 
            +
                    version: 1.0.0
         | 
| 39 39 | 
             
              type: :development
         | 
| 40 40 | 
             
              prerelease: false
         | 
| 41 41 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| @@ -43,7 +43,7 @@ dependencies: | |
| 43 43 | 
             
                requirements:
         | 
| 44 44 | 
             
                - - ~>
         | 
| 45 45 | 
             
                  - !ruby/object:Gem::Version
         | 
| 46 | 
            -
                    version: 0. | 
| 46 | 
            +
                    version: 1.0.0
         | 
| 47 47 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 48 48 | 
             
              name: rdf
         | 
| 49 49 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -51,7 +51,7 @@ dependencies: | |
| 51 51 | 
             
                requirements:
         | 
| 52 52 | 
             
                - - ~>
         | 
| 53 53 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 | 
            -
                    version: 0.3 | 
| 54 | 
            +
                    version: 1.0.3
         | 
| 55 55 | 
             
              type: :runtime
         | 
| 56 56 | 
             
              prerelease: false
         | 
| 57 57 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| @@ -59,7 +59,7 @@ dependencies: | |
| 59 59 | 
             
                requirements:
         | 
| 60 60 | 
             
                - - ~>
         | 
| 61 61 | 
             
                  - !ruby/object:Gem::Version
         | 
| 62 | 
            -
                    version: 0.3 | 
| 62 | 
            +
                    version: 1.0.3
         | 
| 63 63 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 64 64 | 
             
              name: httparty
         | 
| 65 65 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -67,7 +67,7 @@ dependencies: | |
| 67 67 | 
             
                requirements:
         | 
| 68 68 | 
             
                - - ~>
         | 
| 69 69 | 
             
                  - !ruby/object:Gem::Version
         | 
| 70 | 
            -
                    version: 0. | 
| 70 | 
            +
                    version: 0.10.2
         | 
| 71 71 | 
             
              type: :runtime
         | 
| 72 72 | 
             
              prerelease: false
         | 
| 73 73 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| @@ -75,7 +75,7 @@ dependencies: | |
| 75 75 | 
             
                requirements:
         | 
| 76 76 | 
             
                - - ~>
         | 
| 77 77 | 
             
                  - !ruby/object:Gem::Version
         | 
| 78 | 
            -
                    version: 0. | 
| 78 | 
            +
                    version: 0.10.2
         | 
| 79 79 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 80 80 | 
             
              name: api_smith
         | 
| 81 81 | 
             
              requirement: !ruby/object:Gem::Requirement
         |