File: test_free_text.py

package info (click to toggle)
pystac-client 0.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 47,416 kB
  • sloc: python: 4,652; sh: 74; makefile: 60
file content (108 lines) | stat: -rw-r--r-- 4,445 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
from pystac_client.free_text import (
    sqlite_text_search,
)


def test_sqlite_single_term() -> None:
    query = "sentinel"
    assert sqlite_text_search(query, {"description": "The sentinel node was true"})
    assert not sqlite_text_search(query, {"description": "No match here"})


def test_sqlite_special_characters() -> None:
    query = "sentinel-2"
    assert sqlite_text_search(query, {"description": "The sentinel-2 node was true"})
    assert not sqlite_text_search(query, {"description": "No, just sentinel-1 here"})

    query = "sentinel+2"
    assert sqlite_text_search(query, {"description": "The sentinel+2 node was true"})
    assert not sqlite_text_search(query, {"description": "No, just sentinel+1 here"})

    query = "sentinel@2"
    assert sqlite_text_search(query, {"description": "The sentinel@2 node was true"})
    assert not sqlite_text_search(query, {"description": "No, just sentinel@1 here"})


def test_sqlite_exact_phrase() -> None:
    query = '"climate model"'
    assert sqlite_text_search(query, {"description": "The climate model is impressive"})
    assert not sqlite_text_search(
        query, {"description": "This model is for climate modeling"}
    )

    # an exact phrase with a comma inside
    query = '"models, etc"'
    assert sqlite_text_search(
        query, {"description": "Produced with equations, and models, etc."}
    )
    assert not sqlite_text_search(query, {"description": "Produced with models"})


def test_sqlite_and_terms_default() -> None:
    query = "climate model"
    assert sqlite_text_search(
        query,
        {
            "description": "Climate change is a significant challenge",
            "keywords": "model, prediction",
        },
    )
    assert sqlite_text_search(
        query, {"description": "The model was developed using climate observation data"}
    )
    assert not sqlite_text_search(query, {"description": "This is an advanced model"})
    assert not sqlite_text_search(query, {"description": "No relevant terms here"})


def test_sqlite_or_terms_explicit() -> None:
    query = "climate OR model"
    assert sqlite_text_search(query, {"description": "Climate discussion"})
    assert sqlite_text_search(query, {"description": "FPGA model creation"})
    assert not sqlite_text_search(query, {"description": "No matching term here"})


def test_sqlite_or_terms_commas() -> None:
    query = "climate,model"
    assert sqlite_text_search(query, {"description": "Climate change is here"})
    assert sqlite_text_search(query, {"description": "They built a model train"})
    assert sqlite_text_search(query, {"description": "It's a climate model!"})
    assert not sqlite_text_search(
        query, {"description": "It's a mathematical equation"}
    )


def test_sqlite_and_terms() -> None:
    query = "climate AND model"
    assert sqlite_text_search(query, {"description": "The climate model is impressive"})
    assert not sqlite_text_search(
        query, {"description": "This climate change discussion"}
    )
    assert not sqlite_text_search(query, {"description": "Advanced model system"})


def test_sqlite_parentheses_grouping() -> None:
    query = "(quick OR brown) AND fox"
    assert sqlite_text_search(query, {"description": "The quick brown fox"})
    assert sqlite_text_search(query, {"description": "A quick fox jumps"})
    assert sqlite_text_search(query, {"description": "brown bear and a fox"})
    assert not sqlite_text_search(query, {"description": "The fox is clever"})

    query = "(quick AND brown) OR (fast AND red)"
    assert sqlite_text_search(query, {"description": "quick brown fox"})
    assert sqlite_text_search(query, {"description": "fast red car"})
    assert not sqlite_text_search(query, {"description": "quick red car"})


def test_sqlite_inclusions_exclusions() -> None:
    query = "quick +brown -fox"
    assert sqlite_text_search(query, {"description": "The quick brown bear"})
    assert not sqlite_text_search(query, {"description": "The quick fox"})
    assert not sqlite_text_search(query, {"description": "The quickest"})
    assert sqlite_text_search(query, {"description": "A quick light brown jumper"})


def test_sqlite_partial_match() -> None:
    query = "climat"
    assert not sqlite_text_search(query, {"description": "climatology"})
    assert not sqlite_text_search(query, {"description": "climate"})
    assert not sqlite_text_search(query, {"description": "climbing"})