pho 0.2 → 0.3

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.
Files changed (140) hide show
  1. data/CHANGES +19 -0
  2. data/Rakefile +6 -4
  3. data/doc/index.html +6 -0
  4. data/doc/rdoc/classes/Pho.html +250 -0
  5. data/doc/rdoc/classes/Pho/Analyzers.html +288 -0
  6. data/doc/rdoc/classes/Pho/DatatypeProperty.html +209 -0
  7. data/doc/rdoc/classes/Pho/DatatypeProperty.src/M000034.html +21 -0
  8. data/doc/rdoc/classes/Pho/DatatypeProperty.src/M000035.html +29 -0
  9. data/doc/rdoc/classes/Pho/Etags.html +238 -0
  10. data/doc/rdoc/classes/Pho/Etags.src/M000088.html +23 -0
  11. data/doc/rdoc/classes/Pho/Etags.src/M000089.html +28 -0
  12. data/doc/rdoc/classes/Pho/Etags.src/M000090.html +21 -0
  13. data/doc/rdoc/classes/Pho/Etags.src/M000091.html +18 -0
  14. data/doc/rdoc/classes/Pho/Etags.src/M000092.html +18 -0
  15. data/doc/rdoc/classes/Pho/Etags.src/M000093.html +18 -0
  16. data/doc/rdoc/classes/Pho/Facet.html +119 -0
  17. data/doc/rdoc/classes/Pho/Facet/Results.html +225 -0
  18. data/doc/rdoc/classes/Pho/Facet/Results.src/M000001.html +20 -0
  19. data/doc/rdoc/classes/Pho/Facet/Results.src/M000002.html +27 -0
  20. data/doc/rdoc/classes/Pho/Facet/Results.src/M000003.html +54 -0
  21. data/doc/rdoc/classes/Pho/Facet/Term.html +166 -0
  22. data/doc/rdoc/classes/Pho/Facet/Term.src/M000004.html +20 -0
  23. data/doc/rdoc/classes/Pho/FieldPredicateMap.html +461 -0
  24. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000005.html +38 -0
  25. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000006.html +28 -0
  26. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000007.html +20 -0
  27. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000008.html +18 -0
  28. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000009.html +23 -0
  29. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000010.html +23 -0
  30. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000011.html +18 -0
  31. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000012.html +18 -0
  32. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000013.html +18 -0
  33. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000014.html +18 -0
  34. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000015.html +18 -0
  35. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000016.html +21 -0
  36. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000017.html +21 -0
  37. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000018.html +38 -0
  38. data/doc/rdoc/classes/Pho/FieldPredicateMap.src/M000019.html +18 -0
  39. data/doc/rdoc/classes/Pho/FieldWeighting.html +202 -0
  40. data/doc/rdoc/classes/Pho/FieldWeighting.src/M000075.html +20 -0
  41. data/doc/rdoc/classes/Pho/FieldWeighting.src/M000076.html +26 -0
  42. data/doc/rdoc/classes/Pho/Job.html +147 -0
  43. data/doc/rdoc/classes/Pho/Job.src/M000074.html +21 -0
  44. data/doc/rdoc/classes/Pho/Namespaces.html +128 -0
  45. data/doc/rdoc/classes/Pho/QueryProfile.html +355 -0
  46. data/doc/rdoc/classes/Pho/QueryProfile.src/M000024.html +39 -0
  47. data/doc/rdoc/classes/Pho/QueryProfile.src/M000025.html +24 -0
  48. data/doc/rdoc/classes/Pho/QueryProfile.src/M000026.html +20 -0
  49. data/doc/rdoc/classes/Pho/QueryProfile.src/M000027.html +18 -0
  50. data/doc/rdoc/classes/Pho/QueryProfile.src/M000028.html +18 -0
  51. data/doc/rdoc/classes/Pho/QueryProfile.src/M000029.html +21 -0
  52. data/doc/rdoc/classes/Pho/QueryProfile.src/M000030.html +18 -0
  53. data/doc/rdoc/classes/Pho/QueryProfile.src/M000031.html +18 -0
  54. data/doc/rdoc/classes/Pho/QueryProfile.src/M000032.html +38 -0
  55. data/doc/rdoc/classes/Pho/QueryProfile.src/M000033.html +18 -0
  56. data/doc/rdoc/classes/Pho/RDFCollection.html +353 -0
  57. data/doc/rdoc/classes/Pho/RDFCollection.src/M000077.html +23 -0
  58. data/doc/rdoc/classes/Pho/RDFCollection.src/M000078.html +22 -0
  59. data/doc/rdoc/classes/Pho/RDFCollection.src/M000079.html +24 -0
  60. data/doc/rdoc/classes/Pho/RDFCollection.src/M000080.html +23 -0
  61. data/doc/rdoc/classes/Pho/RDFCollection.src/M000081.html +18 -0
  62. data/doc/rdoc/classes/Pho/RDFCollection.src/M000082.html +22 -0
  63. data/doc/rdoc/classes/Pho/RDFCollection.src/M000083.html +22 -0
  64. data/doc/rdoc/classes/Pho/RDFCollection.src/M000084.html +26 -0
  65. data/doc/rdoc/classes/Pho/RDFCollection.src/M000085.html +23 -0
  66. data/doc/rdoc/classes/Pho/RDFCollection.src/M000086.html +18 -0
  67. data/doc/rdoc/classes/Pho/RDFCollection.src/M000087.html +18 -0
  68. data/doc/rdoc/classes/Pho/Snapshot.html +271 -0
  69. data/doc/rdoc/classes/Pho/Snapshot.src/M000070.html +31 -0
  70. data/doc/rdoc/classes/Pho/Snapshot.src/M000071.html +21 -0
  71. data/doc/rdoc/classes/Pho/Snapshot.src/M000072.html +18 -0
  72. data/doc/rdoc/classes/Pho/Snapshot.src/M000073.html +37 -0
  73. data/doc/rdoc/classes/Pho/Status.html +245 -0
  74. data/doc/rdoc/classes/Pho/Status.src/M000020.html +20 -0
  75. data/doc/rdoc/classes/Pho/Status.src/M000021.html +31 -0
  76. data/doc/rdoc/classes/Pho/Status.src/M000022.html +18 -0
  77. data/doc/rdoc/classes/Pho/Status.src/M000023.html +18 -0
  78. data/doc/rdoc/classes/Pho/Store.html +1055 -0
  79. data/doc/rdoc/classes/Pho/Store.src/M000036.html +22 -0
  80. data/doc/rdoc/classes/Pho/Store.src/M000037.html +18 -0
  81. data/doc/rdoc/classes/Pho/Store.src/M000038.html +25 -0
  82. data/doc/rdoc/classes/Pho/Store.src/M000039.html +20 -0
  83. data/doc/rdoc/classes/Pho/Store.src/M000040.html +20 -0
  84. data/doc/rdoc/classes/Pho/Store.src/M000041.html +28 -0
  85. data/doc/rdoc/classes/Pho/Store.src/M000042.html +23 -0
  86. data/doc/rdoc/classes/Pho/Store.src/M000043.html +18 -0
  87. data/doc/rdoc/classes/Pho/Store.src/M000044.html +18 -0
  88. data/doc/rdoc/classes/Pho/Store.src/M000045.html +18 -0
  89. data/doc/rdoc/classes/Pho/Store.src/M000046.html +18 -0
  90. data/doc/rdoc/classes/Pho/Store.src/M000047.html +23 -0
  91. data/doc/rdoc/classes/Pho/Store.src/M000048.html +22 -0
  92. data/doc/rdoc/classes/Pho/Store.src/M000049.html +26 -0
  93. data/doc/rdoc/classes/Pho/Store.src/M000050.html +24 -0
  94. data/doc/rdoc/classes/Pho/Store.src/M000051.html +20 -0
  95. data/doc/rdoc/classes/Pho/Store.src/M000052.html +20 -0
  96. data/doc/rdoc/classes/Pho/Store.src/M000053.html +25 -0
  97. data/doc/rdoc/classes/Pho/Store.src/M000054.html +20 -0
  98. data/doc/rdoc/classes/Pho/Store.src/M000055.html +30 -0
  99. data/doc/rdoc/classes/Pho/Store.src/M000056.html +21 -0
  100. data/doc/rdoc/classes/Pho/Store.src/M000057.html +23 -0
  101. data/doc/rdoc/classes/Pho/Store.src/M000058.html +28 -0
  102. data/doc/rdoc/classes/Pho/Store.src/M000059.html +18 -0
  103. data/doc/rdoc/classes/Pho/Store.src/M000060.html +18 -0
  104. data/doc/rdoc/classes/Pho/Store.src/M000061.html +18 -0
  105. data/doc/rdoc/classes/Pho/Store.src/M000062.html +31 -0
  106. data/doc/rdoc/classes/Pho/Store.src/M000063.html +21 -0
  107. data/doc/rdoc/classes/Pho/Store.src/M000064.html +20 -0
  108. data/doc/rdoc/classes/Pho/Store.src/M000065.html +20 -0
  109. data/doc/rdoc/classes/Pho/Store.src/M000066.html +20 -0
  110. data/doc/rdoc/classes/Pho/Store.src/M000067.html +20 -0
  111. data/doc/rdoc/classes/Pho/Store.src/M000068.html +20 -0
  112. data/doc/rdoc/classes/Pho/Store.src/M000069.html +20 -0
  113. data/doc/rdoc/created.rid +1 -1
  114. data/doc/rdoc/files/CHANGES.html +140 -0
  115. data/doc/rdoc/files/README.html +9 -8
  116. data/doc/rdoc/files/lib/pho/etags_rb.html +108 -0
  117. data/doc/rdoc/files/lib/pho/facet_rb.html +101 -0
  118. data/doc/rdoc/files/lib/pho/field_predicate_map_rb.html +101 -0
  119. data/doc/rdoc/files/lib/pho/job_rb.html +101 -0
  120. data/doc/rdoc/files/lib/pho/query_profile_rb.html +101 -0
  121. data/doc/rdoc/files/lib/pho/rdf_collection_rb.html +101 -0
  122. data/doc/rdoc/files/lib/pho/snapshot_rb.html +108 -0
  123. data/doc/rdoc/files/lib/pho/status_rb.html +101 -0
  124. data/doc/rdoc/files/lib/pho/store_rb.html +101 -0
  125. data/doc/rdoc/files/lib/pho_rb.html +120 -0
  126. data/doc/rdoc/fr_class_index.html +16 -0
  127. data/doc/rdoc/fr_file_index.html +11 -0
  128. data/doc/rdoc/fr_method_index.html +93 -0
  129. data/examples/status.rb +3 -3
  130. data/lib/pho.rb +11 -2
  131. data/lib/pho/facet.rb +101 -0
  132. data/lib/pho/field_predicate_map.rb +4 -4
  133. data/lib/pho/query_profile.rb +170 -0
  134. data/lib/pho/status.rb +65 -0
  135. data/lib/pho/store.rb +26 -13
  136. data/tests/tc_facet.rb +91 -0
  137. data/tests/tc_query_profile.rb +196 -0
  138. data/tests/tc_status.rb +56 -0
  139. data/tests/ts_pho.rb +3 -0
  140. metadata +148 -3
@@ -0,0 +1,65 @@
1
+ module Pho
2
+
3
+ #Can only read data
4
+ READ_ONLY = "http://schemas.talis.com/2006/bigfoot/statuses#read-only".freeze
5
+ #Can read and write data
6
+ READ_WRITE = "http://schemas.talis.com/2006/bigfoot/statuses#read-write".freeze
7
+ #Cannot access the store
8
+ UNAVAILABLE = "http://schemas.talis.com/2006/bigfoot/statuses#unavailable".freeze
9
+
10
+ #Captures status information relating to a store
11
+ class Status
12
+
13
+ #Interval before status should be requested again.
14
+ attr_reader :retry_interval
15
+
16
+ #Status message
17
+ attr_reader :status_message
18
+
19
+ #Current access mode uri
20
+ #
21
+ #This will be one of Pho::READ_ONLY, Pho::READ_WRITE, or Pho::UNAVAILABLE. Use the
22
+ #readable and writeable methods to test for the different modes
23
+ attr_reader :access_mode
24
+
25
+ def initialize(retry_interval, status_message, access_mode)
26
+ @retry_interval = retry_interval
27
+ @status_message = status_message
28
+ @access_mode = access_mode
29
+ end
30
+
31
+ #Create a Status object by reading the response from a store access status request
32
+ #
33
+ #The code parses the JSON output from the Platform API to create a Status object.
34
+ #
35
+ #store:: the store whose status is to be read
36
+ def Status.read_from_store(store)
37
+ response = store.get_status()
38
+ if (response.status != 200)
39
+ raise "Cannot read store status"
40
+ end
41
+
42
+ u = store.build_uri("/config/access-status")
43
+ json = JSON.parse( response.content )
44
+ retry_interval = json[u]["http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#retryInterval"][0]["value"]
45
+ status_message = json[u]["http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#statusMessage"][0]["value"]
46
+ access_mode = json[u]["http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#accessMode"][0]["value"]
47
+
48
+ state = Status.new(retry_interval.to_i, status_message, access_mode)
49
+ return state
50
+
51
+ end
52
+
53
+ #Is the store readable?
54
+ def readable?
55
+ return @access_mode != Pho::UNAVAILABLE
56
+ end
57
+
58
+ #Is the store writeable?
59
+ def writeable?
60
+ return @access_mode == Pho::READ_WRITE
61
+ end
62
+
63
+ end
64
+
65
+ end
@@ -2,16 +2,12 @@ module Pho
2
2
 
3
3
  #TODO:
4
4
  #
5
+ # Make it work with Ruby < 1.8.7
5
6
  # Changesets
6
7
  # Multisparql
7
8
  #
8
9
  # Listing jobs
9
10
  # Retrieving single job
10
- # FP Map
11
- # Query Profile
12
- # List snapshots
13
- # Get snapshot
14
- #
15
11
  #
16
12
  # Conditional deletions
17
13
  # If-Modified-Since support
@@ -402,15 +398,10 @@ module Pho
402
398
  # ADMIN
403
399
  #############
404
400
 
405
- def status()
401
+ def get_status()
406
402
  u = build_uri("/config/access-status")
407
- response = @client.get_content(u, nil, ACCEPT_JSON )
408
- json = JSON.parse( response )
409
- state = Hash.new
410
- state["retryInterval"] = json[u.to_s]["http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#retryInterval"][0]["value"]
411
- state["statusMessage"] = json[u.to_s]["http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#statusMessage"][0]["value"]
412
- state["accessMode"] = json[u.to_s]["http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#accessMode"][0]["value"]
413
- return state
403
+ response = @client.get(u, nil, ACCEPT_JSON )
404
+ return response
414
405
  end
415
406
 
416
407
  # Retrieve the list of snapshots for this store
@@ -447,6 +438,28 @@ module Pho
447
438
  headers = {"Content-Type" => "application/rdf+xml"}
448
439
  return @client.put(u, data, headers)
449
440
  end
441
+
442
+ #Read the query profile configuration for this store. The config can be requested in any
443
+ #format supported by the platform, but the default will return JSON. See QueryProfile.read_from_store
444
+ #for a convenient way to quickly create a QueryProfile object based on a specific stores's configuration.
445
+ #
446
+ #output:: mimetype to use in request
447
+ def get_query_profile(output=ACCEPT_JSON)
448
+ u = build_uri("/config/queryprofiles/1")
449
+ response = @client.get(u, nil, output)
450
+ return response
451
+ end
452
+
453
+ #Update/replace the current Query Profile configuration in the store. Assumes that the provided
454
+ #data is valid RDF/XML. Use QueryProfile.upload as a convenience function
455
+ #
456
+ #data:: a string containing an RDF/XML document
457
+ def put_query_profile(data)
458
+ u = build_uri("/config/queryprofiles/1")
459
+ headers = {"Content-Type" => "application/rdf+xml"}
460
+ return @client.put(u, data, headers)
461
+ end
462
+
450
463
  end
451
464
 
452
465
  end
@@ -0,0 +1,91 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+ require 'pho'
3
+ require 'test/unit'
4
+ require 'mocha'
5
+ require 'rexml/document'
6
+
7
+ class FacetTest < Test::Unit::TestCase
8
+
9
+ RESULTS = <<-EOL
10
+ <facet-results xmlns="http://schemas.talis.com/2007/facet-results#">
11
+ <head>
12
+ <query>austen</query>
13
+ <fields>title,author,publisher</fields>
14
+ </head>
15
+ <fields>
16
+ <field name="title">
17
+ <term number="19" search-uri="http://api.talis.com/stores/testing/items?query=austen+title:%22Pride+and+prejudice%22">Pride and prejudice</term>
18
+ <term number="12" search-uri="http://api.talis.com/stores/testing/items?query=austen+title:%22Emma%22">Emma</term>
19
+ <term number="9" search-uri="http://api.talis.com/stores/testing/items?query=austen+title:%22Northanger+Abbey%22">Northanger Abbey</term>
20
+ <term number="8" search-uri="http://api.talis.com/stores/testing/items?query=austen+title:%22Mansfield+Park%22">Mansfield Park</term>
21
+ </field>
22
+ <field name="publisher"/>
23
+
24
+ <field name="author">
25
+ <term number="91" search-uri="http://api.talis.com/stores/testing/items?query=austen+author:%22Austen,+Jane%22">Austen, Jane</term>
26
+ <term number="6" search-uri="http://api.talis.com/stores/testing/items?query=austen+author:%22Jane+Austen+Society.%22">Jane Austen Society.</term>
27
+ <term number="3" search-uri="http://api.talis.com/stores/testing/items?query=austen+author:%22Evans,+J.+M.+(Jessie+Maud)%22">Evans, J. M. (Jessie Maud)</term>
28
+ <term number="3" search-uri="http://api.talis.com/stores/testing/items?query=austen+author:%22Chapman,+R.+W.+(Robert+William)%22">Chapman, R. W. (Robert William)</term>
29
+ </field>
30
+
31
+ </fields>
32
+
33
+ </facet-results>
34
+ EOL
35
+
36
+ def test_parse
37
+
38
+ results = Pho::Facet::Results.parse(RESULTS)
39
+
40
+ assert_equal("austen", results.query)
41
+ assert_equal("title,author,publisher", results.fields)
42
+ assert_equal(3, results.facets.size)
43
+
44
+ assert_equal(4, results.facets["title"].length)
45
+ assert_expected_term(results.facets["title"][0],
46
+ 19, "http://api.talis.com/stores/testing/items?query=austen+title:%22Pride+and+prejudice%22", "Pride and prejudice")
47
+ assert_expected_term(results.facets["title"][1],
48
+ 12, "http://api.talis.com/stores/testing/items?query=austen+title:%22Emma%22", "Emma")
49
+ assert_expected_term(results.facets["title"][2],
50
+ 9, "http://api.talis.com/stores/testing/items?query=austen+title:%22Northanger+Abbey%22", "Northanger Abbey")
51
+ assert_expected_term(results.facets["title"][3],
52
+ 8, "http://api.talis.com/stores/testing/items?query=austen+title:%22Mansfield+Park%22", "Mansfield Park")
53
+
54
+ assert_equal(0, results.facets["publisher"].length)
55
+
56
+ assert_equal(4, results.facets["author"].length)
57
+ assert_expected_term(results.facets["author"][0],
58
+ 91, "http://api.talis.com/stores/testing/items?query=austen+author:%22Austen,+Jane%22", "Austen, Jane")
59
+ assert_expected_term(results.facets["author"][1],
60
+ 6, "http://api.talis.com/stores/testing/items?query=austen+author:%22Jane+Austen+Society.%22", "Jane Austen Society.")
61
+ assert_expected_term(results.facets["author"][2],
62
+ 3, "http://api.talis.com/stores/testing/items?query=austen+author:%22Evans,+J.+M.+(Jessie+Maud)%22", "Evans, J. M. (Jessie Maud)")
63
+ assert_expected_term(results.facets["author"][3],
64
+ 3, "http://api.talis.com/stores/testing/items?query=austen+author:%22Chapman,+R.+W.+(Robert+William)%22", "Chapman, R. W. (Robert William)")
65
+
66
+ end
67
+
68
+ def test_read_from_store
69
+ mc = mock()
70
+ mc.expects(:set_auth)
71
+ mc.expects(:get).with("http://api.talis.com/stores/testing/services/facet",
72
+ {"query" => "austen", "fields" => "title,author,publisher", "output" => "xml"}, nil).returns(
73
+ HTTP::Message.new_response(RESULTS))
74
+
75
+ store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
76
+
77
+ results = Pho::Facet::Results.read_from_store(store, "austen", ["title", "author", "publisher"])
78
+
79
+ assert_not_nil(results)
80
+ assert_equal("austen", results.query)
81
+ assert_equal("title,author,publisher", results.fields)
82
+ assert_equal(3, results.facets.size)
83
+
84
+ end
85
+
86
+ def assert_expected_term(term, hits, search_uri, value)
87
+ assert_equal(hits, term.hits)
88
+ assert_equal(search_uri, term.search_uri)
89
+ assert_equal(value, term.value)
90
+ end
91
+ end
@@ -0,0 +1,196 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+ require 'pho'
3
+ require 'test/unit'
4
+ require 'mocha'
5
+ require 'rexml/document'
6
+
7
+ class QueryProfileTest < Test::Unit::TestCase
8
+
9
+ QP_JSON = <<-EOL
10
+ {
11
+ "http:\/\/api.talis.com\/stores\/testing\/config\/queryprofiles\/1" : {
12
+ "http:\/\/www.w3.org\/2000\/01\/rdf-schema#label" : [ { "value" : "default query profile", "type" : "literal" } ],
13
+ "http:\/\/www.w3.org\/1999\/02\/22-rdf-syntax-ns#type" : [ { "value" : "http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#QueryProfile", "type" : "uri" } ],
14
+ "http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#fieldWeight" : [
15
+ { "value" : "http:\/\/api.talis.com\/stores\/testing\/config\/queryprofiles\/1#name", "type" : "uri" },
16
+ { "value" : "http:\/\/api.talis.com\/stores\/testing\/config\/queryprofiles\/1#nick", "type" : "uri" }
17
+ ]
18
+ },
19
+ "http:\/\/api.talis.com\/stores\/testing\/config\/queryprofiles\/1#nick" : {
20
+ "http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#weight" : [ { "value" : "1.0", "type" : "literal" } ],
21
+ "http:\/\/schemas.talis.com\/2006\/frame\/schema#name" : [ { "value" : "nick", "type" : "literal" } ]
22
+ },
23
+ "http:\/\/api.talis.com\/stores\/testing\/config\/queryprofiles\/1#name" : {
24
+ "http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#weight" : [ { "value" : "2.0", "type" : "literal" } ],
25
+ "http:\/\/schemas.talis.com\/2006\/frame\/schema#name" : [ { "value" : "name", "type" : "literal" } ]
26
+ }
27
+ }
28
+ EOL
29
+
30
+ def setup
31
+ @qp = Pho::QueryProfile.new("http://api.talis.com/stores/testing/config/queryprofiles/default", "test query profile")
32
+
33
+ @qp << Pho::FieldWeighting.new("http://api.talis.com/stores/testing/config/queryprofiles/default#title","title", 10)
34
+ @qp << Pho::FieldWeighting.new("http://api.talis.com/stores/testing/config/queryprofiles/default#abstract", "abstract", 5)
35
+ @qp << Pho::FieldWeighting.new("http://api.talis.com/stores/testing/config/queryprofiles/default#body", "body", 1)
36
+
37
+ end
38
+
39
+ def test_field_weighting
40
+
41
+ fw = Pho::FieldWeighting.new("http://api.talis.com/stores/testing/config/queryprofiles/default#title", "title", 10)
42
+
43
+ rdf = fw.to_rdf
44
+
45
+ assert_equal(true, rdf != nil)
46
+
47
+ #Check it parses
48
+ doc = nil
49
+ assert_nothing_raised {
50
+ doc = REXML::Document.new(rdf)
51
+ }
52
+
53
+ root = doc.root
54
+ assert_equal("http://api.talis.com/stores/testing/config/queryprofiles/default#title", root.attributes["about"])
55
+
56
+ assert_has_single_property_with_literal(root, "frm:name", "title")
57
+ assert_has_single_property_with_literal(root, "bf:weight", "10")
58
+
59
+ end
60
+
61
+
62
+ def assert_has_single_property_with_literal(el, property, value)
63
+
64
+ assert_equal(1, el.get_elements(property).length)
65
+ child = el.get_elements(property)[0]
66
+ assert_equal(value, child.text)
67
+
68
+ end
69
+
70
+ def test_to_rdf
71
+ rdf = @qp.to_rdf
72
+
73
+ assert_equal(true, rdf != nil)
74
+
75
+ #Check it parses
76
+ doc = nil
77
+ assert_nothing_raised {
78
+ doc = REXML::Document.new(rdf)
79
+ }
80
+
81
+ root = doc.root
82
+
83
+ children = root.get_elements("rdf:Description")
84
+ #fpmap + 3 mappings
85
+ assert_equal(4, children.length)
86
+
87
+ fpmap = children[0]
88
+ assert_has_single_property_with_literal(fpmap, "rdfs:label", "test query profile")
89
+
90
+ end
91
+
92
+ def test_get_query_profile_from_store
93
+ mc = mock()
94
+ mc.expects(:set_auth)
95
+ mc.expects(:get).with("http://api.talis.com/stores/testing/config/queryprofiles/1", anything, {"Accept" => "application/json"})
96
+
97
+ store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
98
+ resp = store.get_query_profile()
99
+
100
+ end
101
+
102
+ def test_get_query_profile_from_store_as_xml
103
+ mc = mock()
104
+ mc.expects(:set_auth)
105
+ mc.expects(:get).with("http://api.talis.com/stores/testing/config/queryprofiles/1", anything, {"Accept" => "application/rdf+xml"})
106
+
107
+ store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
108
+ resp = store.get_query_profile(Pho::ACCEPT_RDF)
109
+ end
110
+
111
+
112
+ def test_read_from_store
113
+ mc = mock()
114
+ mc.expects(:set_auth)
115
+ mc.expects(:get).with("http://api.talis.com/stores/testing/config/queryprofiles/1", anything,
116
+ {"Accept" => "application/json"}).returns( HTTP::Message.new_response(QP_JSON) )
117
+
118
+ store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
119
+ qp = Pho::QueryProfile.read_from_store(store)
120
+
121
+ assert_not_nil(qp)
122
+
123
+ assert_equal("http://api.talis.com/stores/testing/config/queryprofiles/1", qp.uri)
124
+ assert_equal("default query profile", qp.label)
125
+
126
+ assert_equal(2, qp.field_weights.length)
127
+
128
+ sorted = qp.field_weights.sort { |x,y|
129
+ x.name <=> y.name
130
+ }
131
+
132
+ assert_expected_field_weighting(sorted[0], "name", "http://api.talis.com/stores/testing/config/queryprofiles/1#name", "2.0")
133
+ assert_expected_field_weighting(sorted[1], "nick", "http://api.talis.com/stores/testing/config/queryprofiles/1#nick", "1.0")
134
+ end
135
+
136
+ def test_get_by_name
137
+
138
+ assert_expected_field_weighting(@qp.get_by_name("abstract"), "abstract", "http://api.talis.com/stores/testing/config/queryprofiles/default#abstract", 5.0)
139
+ assert_expected_field_weighting(@qp.get_by_name("title"), "title", "http://api.talis.com/stores/testing/config/queryprofiles/default#title", 10.0)
140
+
141
+ end
142
+
143
+ def test_create_weighting
144
+
145
+ store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass")
146
+ weight = Pho::QueryProfile.create_weighting(store, "title", 2)
147
+
148
+ assert_expected_field_weighting(weight, "title", "http://api.talis.com/stores/testing/config/queryprofiles/1#title", 2)
149
+
150
+ end
151
+
152
+ def assert_expected_field_weighting(fw, name, uri, weight)
153
+ assert_equal(name, fw.name)
154
+ assert_equal(uri, fw.uri)
155
+ assert_equal(weight, fw.weight)
156
+ end
157
+
158
+ def test_remove
159
+ fw = @qp.get_by_name("title")
160
+ assert_not_nil(fw)
161
+ @qp.remove(fw)
162
+ fw = @qp.get_by_name("title")
163
+ assert_nil(fw)
164
+
165
+ fw = @qp.get_by_name("abstract")
166
+ assert_not_nil(fw)
167
+ @qp.remove_by_name("abstract")
168
+ fw = @qp.get_by_name("abstract")
169
+ assert_nil(fw)
170
+
171
+ assert_equal(false, @qp.mapped_name?("title"))
172
+ assert_equal(false, @qp.mapped_name?("abstract"))
173
+ assert_equal(true, @qp.mapped_name?("body"))
174
+ assert_equal(1, @qp.field_weights.length)
175
+ end
176
+
177
+ def test_put_query_profile
178
+ mc = mock()
179
+ mc.expects(:set_auth)
180
+ mc.expects(:put).with("http://api.talis.com/stores/testing/config/queryprofiles/1", anything, {"Content-Type" => "application/rdf+xml"} )
181
+
182
+ store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
183
+ resp = store.put_query_profile(@qp)
184
+ end
185
+
186
+ def test_upload_to_store
187
+ mc = mock()
188
+ mc.expects(:set_auth)
189
+ mc.expects(:put).with("http://api.talis.com/stores/testing/config/queryprofiles/1", anything, {"Content-Type" => "application/rdf+xml"} )
190
+
191
+ store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
192
+ @qp.upload(store)
193
+
194
+ end
195
+
196
+ end
@@ -0,0 +1,56 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+ require 'pho'
3
+ require 'test/unit'
4
+
5
+ class StatusTest < Test::Unit::TestCase
6
+
7
+ STATUS = <<-EOL
8
+ {
9
+ "http:\/\/api.talis.com\/stores\/testing\/config\/access-status" : {
10
+ "http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#accessMode" : [ { "value" : "http:\/\/schemas.talis.com\/2006\/bigfoot\/statuses#read-write", "type" : "uri" } ],
11
+ "http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#retryInterval" : [ { "value" : "0", "type" : "literal" } ],
12
+ "http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#statusMessage" : [ { "value" : "message", "type" : "literal" } ]
13
+ }
14
+ }
15
+ EOL
16
+
17
+ def test_store_status
18
+ mc = mock()
19
+ mc.expects(:set_auth)
20
+ mc.expects(:get).with("http://api.talis.com/stores/testing/config/access-status", nil, {"Accept" => "application/json"})
21
+
22
+ store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
23
+
24
+ store.get_status()
25
+
26
+ end
27
+
28
+ def test_read_from_store
29
+ mc = mock()
30
+ mc.expects(:set_auth)
31
+ mc.expects(:get).with("http://api.talis.com/stores/testing/config/access-status", nil, {"Accept" => "application/json"}).returns( HTTP::Message.new_response(STATUS) )
32
+
33
+ store = Pho::Store.new("http://api.talis.com/stores/testing", "user", "pass", mc)
34
+
35
+ status = Pho::Status.read_from_store(store)
36
+
37
+ assert_equal(Pho::READ_WRITE, status.access_mode)
38
+ assert_equal(0, status.retry_interval)
39
+ assert_equal("message", status.status_message)
40
+ end
41
+
42
+ def test_read_write
43
+ status = Pho::Status.new(0, "test", Pho::UNAVAILABLE)
44
+ assert_equal(false, status.readable?)
45
+ assert_equal(false, status.writeable?)
46
+
47
+ status = Pho::Status.new(0, "test", Pho::READ_ONLY)
48
+ assert_equal(true, status.readable?)
49
+ assert_equal(false, status.writeable?)
50
+
51
+ status = Pho::Status.new(0, "test", Pho::READ_WRITE)
52
+ assert_equal(true, status.readable?)
53
+ assert_equal(true, status.writeable?)
54
+
55
+ end
56
+ end