File size: 2,559 Bytes
9ff0a35
 
 
 
 
fd342b4
 
 
 
 
 
05a2a0c
9ff0a35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99a52d8
 
 
 
 
9ff0a35
99a52d8
9ff0a35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
using Oxygen
using HTTP
import OstreaCultura as OC

# Load the fasttext embeddings and the fasttext model
tmp_destination = tempname()
# Decompress the fact check data 
OC.decompress_csv("data/fc_latest_maxi_compr", tmp_destination)

#####
const (fc_embed, fc) = OC.load_fasttext_embeddings(tmp_destination)
const (nar_embed, nar) = OC.load_fasttext_embeddings("data/expansive_claims_library_expanded_embed_maxi.csv")

@get "/greet" function(req::HTTP.Request)
    return "hello world!"
end

## Send a query to the test-index index in the test-namespace namespace
#@get "/query" function(req::HTTP.Request, querytext::String, indexname::String, namespace::String, top_k::Int64=5, include_values::Bool=false)
#    OC.query(querytext, indexname, namespace; top_k=top_k, include_values=include_values)
#end

## Send a query to look for matches within an organic dataset 
#@get "/queryclaims" function(req::HTTP.Request, claim::String, counterclaim::String, indexname::String, namespace::String, top_k::Int64=5000, include_values::Bool=false)
#    OC.query_claims(claim, counterclaim, indexname, namespace; top_k=top_k, include_values=include_values)
#end

## Classify a claim within the misinformation library 
#@get "/classify" function(req::HTTP.Request, claim::String, counterclaim::String, indexname::String, namespace::String, top_k::Int64=10, include_values::Bool=false)
#    OC.classify_claim(claim, counterclaim, indexname, namespace; top_k=top_k, include_values=include_values)
#end

# Model is really 'namespace' in the OC library
#@get "/search" function(req::HTTP.Request, claim::String, model::String="narratives", top_k::Int64=5)
#    # remove % signs from claim, replace with percent 
#    claim = replace(claim, "%" => "percent")
#    OC.search(claim, "oc-hybrid-library-index", model; top_k=top_k, include_values=false)
#end

@get "/fastfactsearch" function(req::HTTP.Request, claim::String, model::String="factchecks", top_k::Int64=5)
    # remove % signs from claim, replace with percent 
    claim = replace(claim, "%" => "percent")
    if model == "narratives"
        json(OC.fast_topk(nar_embed, nar, claim, top_k))
    elseif model == "factchecks"
        json(OC.fast_topk(fc_embed, fc, claim, top_k))
    else
        "Model not found"
    end
end

#@get "/searchplot" function(req::HTTP.Request, claim::String, model::String, top_k::Int64=5, include_values::Bool=false)
#    OC.searchplot(claim, "oc-hybrid-library-index", model; top_k=top_k, include_values=include_values)
#end

# start the web server
serve(host="0.0.0.0", port=8000)