|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +# |
| 4 | +require 'test_helper' |
| 5 | + |
| 6 | +class PreprocessorPrimoTest < ActiveSupport::TestCase |
| 7 | + test 'to_tacos returns unhandled for complex queries' do |
| 8 | + input = 'any,contains,space;;;any,contains,madness' |
| 9 | + |
| 10 | + assert_equal('unhandled complex primo query', PreprocessorPrimo.to_tacos(input)) |
| 11 | + end |
| 12 | + |
| 13 | + test 'to_tacos returns unhandled for targeted field queries' do |
| 14 | + input = 'title,contains,space' |
| 15 | + |
| 16 | + assert_equal('unhandled complex primo query', PreprocessorPrimo.to_tacos(input)) |
| 17 | + end |
| 18 | + |
| 19 | + test 'to_tacos returns phrase ready for tacos for simple keyword input' do |
| 20 | + input = 'any,contains,space' |
| 21 | + |
| 22 | + assert_equal('space', PreprocessorPrimo.to_tacos(input)) |
| 23 | + end |
| 24 | + |
| 25 | + test 'to_tacos returns phrase ready for complex keyword input' do |
| 26 | + input = 'any,contains,Yan, F., Krantz, P., Sung, Y., Kjaergaard, M., Campbell, D.L., Orlando, T.P., Gustavsson, S. and Oliver, W.D., 2018. Tunable coupling scheme for implementing high-fidelity two-qubit gates. Physical Review Applied, 10(5), p.054062.' |
| 27 | + expected = 'Yan, F., Krantz, P., Sung, Y., Kjaergaard, M., Campbell, D.L., Orlando, T.P., Gustavsson, S. and Oliver, W.D., 2018. Tunable coupling scheme for implementing high-fidelity two-qubit gates. Physical Review Applied, 10(5), p.054062.' |
| 28 | + |
| 29 | + assert_equal(expected, PreprocessorPrimo.to_tacos(input)) |
| 30 | + end |
| 31 | + |
| 32 | + test 'keyword? returns true for any contains phrase pattern' do |
| 33 | + input = 'any,contains,popcorn anomoly'.split(',') |
| 34 | + |
| 35 | + assert(PreprocessorPrimo.keyword?(input)) |
| 36 | + end |
| 37 | + |
| 38 | + test 'keyword? returns false for input with more than 3 array elements' do |
| 39 | + # NOTE: this query entering tacos would work... but it would have been cleaned up prior to running |
| 40 | + # keyword? in our application via the normal flow |
| 41 | + input = 'any,contains,popcorn anomoly: why life on the moon is complex, and other cat facts'.split(',') |
| 42 | + |
| 43 | + assert_not(PreprocessorPrimo.keyword?(input)) |
| 44 | + end |
| 45 | + |
| 46 | + test 'keyword? returns false for input with less than 3 array elements' do |
| 47 | + input = 'any,contains'.split(',') |
| 48 | + |
| 49 | + assert_not(PreprocessorPrimo.keyword?(input)) |
| 50 | + end |
| 51 | + |
| 52 | + test 'keyword? returns false for non-any input' do |
| 53 | + input = 'title,contains,popcorn anomoly'.split(',') |
| 54 | + |
| 55 | + assert_not(PreprocessorPrimo.keyword?(input)) |
| 56 | + end |
| 57 | + |
| 58 | + test 'keyword? returns true for non-contains inputs' do |
| 59 | + # NOTE: this portion of they primo query focuses on how to handle the phrase. All the words, any of the words, |
| 60 | + # the exact phrase, begins_with. For now we treat them all the same as standard keyword queries. |
| 61 | + input = 'any,exact,popcorn anomoly'.split(',') |
| 62 | + |
| 63 | + assert(PreprocessorPrimo.keyword?(input)) |
| 64 | + end |
| 65 | + |
| 66 | + test 'extract keyword returns keyword for simple keywords' do |
| 67 | + input = 'any,contains,popcorn anomoly' |
| 68 | + |
| 69 | + assert_equal('popcorn anomoly', PreprocessorPrimo.extract_keyword(input)) |
| 70 | + end |
| 71 | + |
| 72 | + test 'extract keyword returns keyword for simple non-contains keywords' do |
| 73 | + input = 'any,exact,popcorn anomoly' |
| 74 | + |
| 75 | + assert_equal('popcorn anomoly', PreprocessorPrimo.extract_keyword(input)) |
| 76 | + end |
| 77 | + |
| 78 | + test 'extract keyword returns unhandled complex primo query for non-any searches' do |
| 79 | + input = 'title,contains,popcorn anomoly' |
| 80 | + |
| 81 | + assert_equal('unhandled complex primo query', PreprocessorPrimo.extract_keyword(input)) |
| 82 | + end |
| 83 | + |
| 84 | + test 'extract keyword returns keyword for keywords with punctuation' do |
| 85 | + input = 'any,contains,popcorn anomoly: a cats! life. on & mars!' |
| 86 | + |
| 87 | + assert_equal('popcorn anomoly: a cats! life. on & mars!', PreprocessorPrimo.extract_keyword(input)) |
| 88 | + end |
| 89 | + |
| 90 | + test 'extract keyword returns keyword for keywords with commas' do |
| 91 | + input = 'any,contains,popcorn anomoly, and so can you' |
| 92 | + |
| 93 | + assert_equal('popcorn anomoly, and so can you', PreprocessorPrimo.extract_keyword(input)) |
| 94 | + end |
| 95 | + |
| 96 | + test 'extract keyword returns keyword for keywords with multiple commas and other punctuation' do |
| 97 | + input = 'any,contains,popcorn anomoly: a cats! life. on & mars!, words, of {truth} (and, also not,)' |
| 98 | + |
| 99 | + assert_equal('popcorn anomoly: a cats! life. on & mars!, words, of {truth} (and, also not,)', |
| 100 | + PreprocessorPrimo.extract_keyword(input)) |
| 101 | + end |
| 102 | +end |
0 commit comments