This is an automated email from the ASF dual-hosted git repository.
aradzinski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/master by this push:
new 9adc67d WIP on scripts.
9adc67d is described below
commit 9adc67d281aa2689d391c092c8d5cfcd8ade68c8
Author: Aaron Radzinski <[email protected]>
AuthorDate: Sun Aug 23 20:37:10 2020 -0700
WIP on scripts.
---
bin/nccurl.cmd | 34 ++++++++++++++++++++++
bin/nccurl.sh | 2 +-
.../src/main/python/ctxword/bin/start_server.sh | 8 +++++
.../ctxword/bin/{suggestion.cmd => suggest.cmd} | 0
nlpcraft/src/main/python/ctxword/bin/suggest.sh | 8 +++++
5 files changed, 51 insertions(+), 1 deletion(-)
diff --git a/bin/nccurl.cmd b/bin/nccurl.cmd
new file mode 100644
index 0000000..67f7bd1
--- /dev/null
+++ b/bin/nccurl.cmd
@@ -0,0 +1,34 @@
+@echo OFF
+
+rem
+rem Licensed to the Apache Software Foundation (ASF) under one or more
+rem contributor license agreements. See the NOTICE file distributed with
+rem this work for additional information regarding copyright ownership.
+rem The ASF licenses this file to You under the Apache License, Version 2.0
+rem (the "License"); you may not use this file except in compliance with
+rem the License. You may obtain a copy of the License at
+rem
+rem http://www.apache.org/licenses/LICENSE-2.0
+rem
+rem Unless required by applicable law or agreed to in writing, software
+rem distributed under the License is distributed on an "AS IS" BASIS,
+rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+rem See the License for the specific language governing permissions and
+rem limitations under the License.
+rem
+
+rem Quick shortcut script for localhost testing with curl (w/o excessive
command line).
+rem
+rem Usage:
+rem - 1st parameter is REST URL unique suffix (i.e. /signin) w/o leading '/'
+rem - 2nd parameter is JSON payload string
+rem
+rem Example usage:
+rem >./nccurl.cmd signin '{"email": "[email protected]", "passwd": "admin"}'
+rem >./nccurl.cmd ask '{"acsTok": "OgJanjDzk", "txt": "Hi!", "mdlId":
"nlpcraft.helloworld.ex"}'
+rem >./nccurl.cmd check '{"acsTok": "OgJanjDzk"}'
+rem
+rem For pretty JSON output pipe curl to 'python -m json.tool':
+rem $./nccurl.sh check '{"acsTok": "OgJanjDzk"}' | python -m json.tool
+
+curl http://localhost:8081/api/v1/%~1 -s -d "%~2" -H "Content-Type:
application/json" | python -m json.tool
diff --git a/bin/nccurl.sh b/bin/nccurl.sh
index 11a204d..0e5491c 100755
--- a/bin/nccurl.sh
+++ b/bin/nccurl.sh
@@ -30,4 +30,4 @@
# For pretty JSON output pipe curl to 'python -m json.tool':
# $./nccurl.sh check '{"acsTok": "OgJanjDzk"}' | python -m json.tool
-curl -s -d"$2" -H 'Content-Type: application/json'
http://localhost:8081/api/v1/$1
+curl -s -d "$2" -H 'Content-Type: application/json'
http://localhost:8081/api/v1/$1
diff --git a/nlpcraft/src/main/python/ctxword/bin/start_server.sh
b/nlpcraft/src/main/python/ctxword/bin/start_server.sh
index 853672c..e9fe116 100755
--- a/nlpcraft/src/main/python/ctxword/bin/start_server.sh
+++ b/nlpcraft/src/main/python/ctxword/bin/start_server.sh
@@ -20,4 +20,12 @@
# ----
# This script may not be suitable for production usage. Please see official
Flask documentation for
# more info on how to deploy Flask applications.
+
+abort() {
+ echo "$1"
+ exit 1
+}
+
+[ -x "$(command -v python3)" ] || abort "'python3' not found."
+
FLASK_APP=server.py python3 -m flask run
diff --git a/nlpcraft/src/main/python/ctxword/bin/suggestion.cmd
b/nlpcraft/src/main/python/ctxword/bin/suggest.cmd
similarity index 100%
rename from nlpcraft/src/main/python/ctxword/bin/suggestion.cmd
rename to nlpcraft/src/main/python/ctxword/bin/suggest.cmd
diff --git a/nlpcraft/src/main/python/ctxword/bin/suggest.sh
b/nlpcraft/src/main/python/ctxword/bin/suggest.sh
index 04f6013..56d400a 100755
--- a/nlpcraft/src/main/python/ctxword/bin/suggest.sh
+++ b/nlpcraft/src/main/python/ctxword/bin/suggest.sh
@@ -41,4 +41,12 @@
# NOTE: You need to have REST server running (see 'start_server.sh' script in
the same folder).
#
+abort() {
+ echo "$1"
+ exit 1
+}
+
+[ -x "$(command -v curl)" ] || abort "'curl' not found."
+[ -x "$(command -v python3)" ] || abort "'python3' not found."
+
curl -d "{\"sentences\": [{\"text\": \"$1\", \"indexes\": [$2]}], \"simple\":
true, \"limit\": 10}" -H 'Content-Type: application/json'
http://localhost:5000/suggestions | python3 -m json.tool