-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·150 lines (140 loc) · 5.76 KB
/
run.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/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 # https://artresearch.net/sparql
# echo $pharos_user # admin
# echo $pharos_password # pharosadmin
# echo $vision_endpoint # https://vision.artresearch.net/sparql
# echo $vision_user # vision
# echo $vision_password # vision
# echo $method # Pastec
# echo $host # http://vision.artresearch.net
# echo $port # 4212
# 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
# PASTEC METHOD
method=pastec
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)
#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
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)
# 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 and update 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"
# MATCH METHOD
method=match
port=8888
# Request existing indexes
image_ids=$(curl -X GET $host:$port/list)
image_ids=$(echo $image_ids | sed 's/ //g')
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)
IDs+="<https://artresearch.net/resource/graph/visual_similarity/${method}> {\n"
#Match 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 match with the image url
search=$(curl -X POST -F url=$url $host:$port/search)
#[SAME]
echo -e "{\"image_id\": ${ID},\n\"image_url\": \"${line}\",\n\"search_results\": [${search}] },"
# Add image in Match
index=$(curl -X POST -F url=$url -F filepath=$ID $host:$port/add)
# Generate ttl file
IDs+="\t<${line}> <https://artresearch.net/resource/vocab/vision/${method}/has_index> \"${ID}\".\n"
ID=$(expr $ID + 1)
done < ./PhotoSimilarity-Workspace/Graphs/image_uris
echo -e "{}]}"
} > "./PhotoSimilarity-Workspace/IDs/${now}_${method}IDs.json"
# Save indexes in a file
IDs+="}"
# 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 and update 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"