-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_Pastec.sh
executable file
·125 lines (115 loc) · 4.14 KB
/
run_Pastec.sh
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
echo
# setting the authentication variables
source authentication.env
# Script Options
if [ $# -eq 1 ]
then
# setting up configuration variables
# source ./config.sh
source $1
else
while getopts ":q:e:m:h:p:v:" opt; do
case $opt in
q)
query="$OPTARG" >&2
;;
e)
endpoint="$OPTARG" >&2
;;
u)
pharos_user="$OPTARG" >&2
;;
w)
pharos_password="$OPTARG" >&2
;;
v)
vision_endpoint="$OPTARG" >&2
;;
r)
vision_user="$OPTARG" >&2
;;
s)
vision_password="$OPTARG" >&2
;;
m)
method="$OPTARG" >&2
;;
h)
host="$OPTARG" >&2
;;
p)
port="$OPTARG" >&2
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
fi
# Optional arguments default configuration
host=${host:-localhost}
method=${method,,}
now=$(date +"%Y-%m-%dT%H-%M-%S")
# echo $query
# echo $endpoint
# echo $pharos_user
# echo $pharos_password
# echo $vision_endpoint
# echo $vision_user
# echo $vision_password
# echo $method
# echo $host
# echo $port
method=pastec
# Construct query evaluation
java -jar target/PhotoSimilarity-0.1-assembly.jar -q $query -p $endpoint -pharos_user $pharos_user -pharos_password $pharos_password -e $vision_endpoint -vision_user $vision_user -vision_password $vision_password -m $method
# PASTEC METHOD
port=4212
# Request existing indexes
image_ids=$(curl -X GET $host:$port/index/imageIds)
echo -e $image_ids > "./PhotoSimilarity-Workspace/${method}_ids.json"
max_id=$(java -jar target/PhotoSimilarity-0.1-assembly.jar -image_ids ./PhotoSimilarity-Workspace/${method}_ids.json -m $method -e $endpoint -pharos_user $pharos_user -pharos_password $pharos_password)
#IDs+="<https://artresearch.net/resource/graph/visual_similarity/${method}> {\n"
#Pastec Photo Similarity Evaluation & Indexing
{
ID=$(expr $max_id + 1)
echo -e "{\"results\" : ["
while read line || [ -n "$line" ]; do
# resize image (based on iiif model)
url=$(java -jar target/PhotoSimilarity-0.1-assembly.jar -image_url $line)
# Search through the images in pastec with the image url
search=$(curl -X POST -d '{"url":"'$url'"}' $host:$port/index/searcher)
echo -e "{\"image_id\": ${ID},\n\"image_url\": \"${line}\",\n\"search_results\": ${search} },"
# Add image in Pastec (POST original)
index=$(curl -X POST -d '{"url":"'$url'"}' $host:$port/index/images/$ID)
# Generate ttl file
#IDs+="\t<${line}> <https://artresearch.net/resource/vocab/vision/${method}/has_index> <https://vision.artresearch.net:${port}/index/images/${ID}>.\n"
#if [[ $(expr $ID % 1000) -eq 0 ]]; then
# write_index=$(curl -X POST -d '{"type":"WRITE", "index_path":"/pastec/build/pastec-index/pharos.dat"}' ${host}:${port}/index/io)
#fi
ID=$(expr $ID + 1)
done < "./PhotoSimilarity-Workspace/Graphs/image_uris${method}"
echo -e "{}]}"
} > "./PhotoSimilarity-Workspace/IDs/${now}_${method}IDs.json"
# Save indexes in a file
# IDs+="}"
write_index=$(curl -X POST -d '{"type":"WRITE", "index_path":"/pastec/build/pastec-index/pharos.dat"}' ${host}:${port}/index/io)
python3 sntxnorm.py "./PhotoSimilarity-Workspace/IDs/${now}_${method}IDs.json"
# Update Pharos
java -jar target/PhotoSimilarity-0.1-assembly.jar -m $method -e $endpoint -pharos_user $pharos_user -pharos_password $pharos_password -json_file "./PhotoSimilarity-Workspace/IDs/${now}_${method}IDs.json" -pharosModel "./PhotoSimilarity-Workspace/IDs/${now}_${method}IDs.ttl"
# Create model to be uploaded to vision
java -jar target/PhotoSimilarity-0.1-assembly.jar -m $method -p $endpoint -pharos_user $pharos_user -pharos_password $pharos_password -e $vision_endpoint -vision_user $vision_user -vision_password $vision_password -visionModel "./PhotoSimilarity-Workspace/IDs/${now}_${method}IDs.json" -log "./PhotoSimilarity-Workspace/Logs/${now}_${method}_error.log"
# upload models to vision
files="./PhotoSimilarity-Workspace/Model/${now}_${method}/*"
for i in $files
do
echo "Uploading: $i"
curl -u $vision_user:$vision_password -X POST -H 'Content-Type:application/x-trig' --data-binary @$i ${vision_blazegraph}'?keepSourceGraphs=true'
sleep 0.1
done