Class: Lbp::Query
- Inherits:
-
Object
- Object
- Lbp::Query
- Defined in:
- lib/lbp/query.rb
Instance Method Summary collapse
- #collection_query(collection_url) ⇒ Object
- #expressionElementQuery(expression_url, type) ⇒ Object
-
#initialize ⇒ Query
constructor
A new instance of Query.
- #item_query(expression_url) ⇒ Object
- #names(item_url) ⇒ Object
- #query(query) ⇒ Object
- #quotes(item_url) ⇒ Object
- #subject(url) ⇒ Object
- #subject_with_short_id(shortid) ⇒ Object
- #zone_info(paragraphurl) ⇒ Object
Constructor Details
#initialize ⇒ Query
Returns a new instance of Query.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/lbp/query.rb', line 6 def initialize @prefixes = " PREFIX owl: <http://www.w3.org/2002/07/owl#> PREFIX dbpedia: <http://dbpedia.org/ontology/> PREFIX dcterms: <http://purl.org/dc/terms/> PREFIX dc: <http://purl.org/dc/elements/1.1/> PREFIX sctap: <http://scta.info/property/> PREFIX sctar: <http://scta.info/resource/> PREFIX sctat: <http://scta.info/text/> PREFIX role: <http://www.loc.gov/loc.terms/relators/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> " end |
Instance Method Details
#collection_query(collection_url) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/lbp/query.rb', line 89 def collection_query(collection_url) query = "#{@prefixes} SELECT ?collectiontitle ?title ?item ?questiontitle ?order ?status ?gitRepository { #{collection_url} <http://scta.info/property/hasStructureItem> ?item . #{collection_url} <http://purl.org/dc/elements/1.1/title> ?collectiontitle . ?item <http://purl.org/dc/elements/1.1/title> ?title . ?item <http://scta.info/property/totalOrderNumber> ?order . ?item <http://scta.info/property/status> ?status . ?item <http://scta.info/property/gitRepository> ?gitRepository . OPTIONAL { ?item <http://scta.info/property/questionTitle> ?questiontitle . } } ORDER BY ?order" result = self.query(query) end |
#expressionElementQuery(expression_url, type) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/lbp/query.rb', line 129 def expressionElementQuery(expression_url, type) # currently assumes expression_url is for a structureType="structureCollection" expression_url = "<#{expression_url}>" elementTypeUrl = "<#{type}>" query = "#{@prefixes} SELECT ?expression ?structureBlock ?resource ?resourceTitle { #{expression_url} <http://scta.info/property/hasStructureItem> ?structureItem . ?structureItem <http://scta.info/property/hasStructureBlock> ?structureBlock . ?structureBlock <http://scta.info/property/hasStructureElement> ?element . ?element <http://scta.info/property/structureElementType> #{elementTypeUrl} . ?element <http://scta.info/property/isPartOfStructureBlock> ?structureBlock . ?element <http://scta.info/property/isInstanceOf> ?resource . ?resource <http://purl.org/dc/elements/1.1/title> ?resourceTitle . } ORDER BY ?resourceTitle " result = self.query(query) end |
#item_query(expression_url) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/lbp/query.rb', line 112 def item_query(expression_url) query = "#{@prefixes} SELECT ?item_title ?transcript ?transcript_title ?transcript_status ?transcript_type ?manifestation { #{expression_url} <http://purl.org/dc/elements/1.1/title> ?item_title . ?manifestation <http://scta.info/property/isManifestationOf> #{expression_url} . ?transcript <http://scta.info/property/isTranscriptionOf> ?manifestation . ?transcript <http://purl.org/dc/elements/1.1/title> ?transcript_title . ?transcript <http://scta.info/property/status> ?transcript_status . ?transcript <http://scta.info/property/transcriptionType> ?transcript_type . }" result = self.query(query) end |
#names(item_url) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/lbp/query.rb', line 151 def names(item_url) item_url = "<#{item_url}>" query = "#{@prefixes} SELECT ?item ?name ?nameTitle ?mentioningItem { #{item_url} <http://scta.info/property/mentions> ?name . ?name <http://purl.org/dc/elements/1.1/title> ?nameTitle . } ORDER BY ?nameTitle " result = self.query(query) end |
#query(query) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/lbp/query.rb', line 22 def query(query) if ENV['SPARQL'] == "local" sparqlendpoint = "http://localhost:3030/ds/query" elsif ENV['SPARQL'] == "staging" sparqlendpoint = "http://sparql-staging.scta.info/ds/query" elsif ENV['RACK_ENV'] == "production" || ENV['SPARQL'] == "production" sparqlendpoint = "http://sparql.scta.info/ds/query" else sparqlendpoint = "http://sparql.scta.info/ds/query" end sparql = SPARQL::Client.new(sparqlendpoint) result = sparql.query(query) return result end |
#quotes(item_url) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/lbp/query.rb', line 166 def quotes(item_url) item_url = "<#{item_url}>" query = "#{@prefixes} SELECT ?item ?quote ?quoteText ?quoteCitation { #{item_url} <http://scta.info/property/quotes> ?quote . ?quote <http://scta.info/property/quotation> ?quoteText . ?quote <http://scta.info/property/citation> ?quoteCitation . } ORDER BY ?quoteText " result = self.query(query) end |
#subject(url) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/lbp/query.rb', line 38 def subject(url) query = "#{@prefixes} SELECT ?p ?o ?ptype { #{url} ?p ?o . OPTIONAL { ?p rdfs:subPropertyOf ?ptype . } } ORDER BY ?p " result = self.query(query) end |
#subject_with_short_id(shortid) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/lbp/query.rb', line 53 def subject_with_short_id(shortid) query = "#{@prefixes} SELECT ?p ?o ?ptype { ?resource <http://scta.info/property/shortId> '#{shortid}' . ?resource ?p ?o . OPTIONAL { ?p rdfs:subPropertyOf ?ptype . } } ORDER BY ?p " result = self.query(query) end |
#zone_info(paragraphurl) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/lbp/query.rb', line 70 def zone_info(paragraphurl) query = "#{@prefixes} SELECT DISTINCT ?zone ?ulx ?uly ?lry ?lrx ?position ?height ?width ?canvasurl { #{paragraphurl} <http://scta.info/property/hasZone> ?zone . ?zone <http://scta.info/property/ulx> ?ulx . ?zone <http://scta.info/property/uly> ?uly . ?zone <http://scta.info/property/lry> ?lry . ?zone <http://scta.info/property/lrx> ?lrx . ?zone <http://scta.info/property/position> ?position . ?zone <http://scta.info/property/height> ?height . ?zone <http://scta.info/property/width> ?width . ?zone <http://scta.info/property/isZoneOn> ?canvasurl . } ORDER BY ?position" result = self.query(query) end |