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 83d0312  Fixing win scripts.
83d0312 is described below

commit 83d031268e53b71f01befa0c7371647b3a8ac5bf
Author: Aaron Radzinski <[email protected]>
AuthorDate: Sun Aug 23 21:21:21 2020 -0700

    Fixing win scripts.
---
 bin/nccurl.cmd                                        | 15 ++++++++-------
 bin/nccurl.sh                                         | 13 +++++++++----
 nlpcraft/src/main/python/ctxword/bin/start_server.cmd |  3 ++-
 nlpcraft/src/main/python/ctxword/bin/suggest.cmd      |  9 +++++----
 4 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/bin/nccurl.cmd b/bin/nccurl.cmd
index 67f7bd1..4ab3740 100644
--- a/bin/nccurl.cmd
+++ b/bin/nccurl.cmd
@@ -21,14 +21,15 @@ rem Quick shortcut script for localhost testing with curl 
(w/o excessive command
 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 - 2nd parameter is JSON payload string (note that double quotes in JSON 
must be escaped).
 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   >./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
+where curl >nul 2>&1 || echo 'curl' not found && exit /b
+where python3 >nul 2>&1 || echo 'python3' not found && exit /b
+
+curl http://localhost:8081/api/v1/%~1 -s -d "%~2" -H "Content-Type: 
application/json" | python3 -m json.tool
diff --git a/bin/nccurl.sh b/bin/nccurl.sh
index 0e5491c..4fc4a42 100755
--- a/bin/nccurl.sh
+++ b/bin/nccurl.sh
@@ -26,8 +26,13 @@
 #   $./nccurl.sh signin '{"email": "[email protected]", "passwd": "admin"}'
 #   $./nccurl.sh ask '{"acsTok": "OgJanjDzk", "txt": "Hi!", "mdlId": 
"nlpcraft.helloworld.ex"}'
 #   $./nccurl.sh check '{"acsTok": "OgJanjDzk"}'
-#
-# 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
+abort() {
+  echo "$1"
+  exit 1
+}
+
+[ -x "$(command -v curl)" ] || abort "'curl' not found."
+[ -x "$(command -v python3)" ] || abort "'python3' not found."
+
+curl -s -d "$2" -H 'Content-Type: application/json' 
http://localhost:8081/api/v1/$1 | python3 -m json.tool
diff --git a/nlpcraft/src/main/python/ctxword/bin/start_server.cmd 
b/nlpcraft/src/main/python/ctxword/bin/start_server.cmd
index 8aa6942..b15c433 100644
--- a/nlpcraft/src/main/python/ctxword/bin/start_server.cmd
+++ b/nlpcraft/src/main/python/ctxword/bin/start_server.cmd
@@ -16,11 +16,12 @@ 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
 rem NOTE:
 rem ----
 rem This script may not be suitable for production usage. Please see official 
Flask documentation for
 rem more info on how to deploy Flask applications.
 
+where python3 >nul 2>&1 || echo 'python3' not found && exit /b
+
 set FLASK_APP=server.py
 python3 -m flask run
\ No newline at end of file
diff --git a/nlpcraft/src/main/python/ctxword/bin/suggest.cmd 
b/nlpcraft/src/main/python/ctxword/bin/suggest.cmd
index b26fe6d..cf267f8 100644
--- a/nlpcraft/src/main/python/ctxword/bin/suggest.cmd
+++ b/nlpcraft/src/main/python/ctxword/bin/suggest.cmd
@@ -16,11 +16,9 @@ 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
-rem
 rem Simple Curl-based script for getting contextual related words suggestions 
for a single input sentence.
 rem Example:
-rem     > bin\win\suggest.cmd "what is the chance of rain tomorrow?" 5
+rem     > bin\suggest.cmd "what is the chance of rain tomorrow?" 5
 rem       % Total    % Received % Xferd  Average Speed   Time    Time     Time 
 Current
 rem                                      Dload  Upload   Total   Spent    Left 
 Speed
 rem     100   214  100   104  100   110    104    110  0:00:01 --:--:--  
0:00:01   804
@@ -42,4 +40,7 @@ rem
 rem NOTE: You need to have REST server running (see 'start_server.{cmd|ps1}' 
scripts in the same folder).
 rem
 
-curl http://localhost:5000/suggestions -d "{\"sentences\": [{\"text\": 
\"%~1\", \"indexes\": [%~2]}], \"simple\": true, \"limit\": 10}" -H 
"Content-Type: application/json" | python -m json.tool
\ No newline at end of file
+where curl >nul 2>&1 || echo 'curl' not found && exit /b
+where python3 >nul 2>&1 || echo 'python3' not found && exit /b
+
+curl http://localhost:5000/suggestions -d "{\"sentences\": [{\"text\": 
\"%~1\", \"indexes\": [%~2]}], \"simple\": true, \"limit\": 10}" -H 
"Content-Type: application/json" | python3 -m json.tool
\ No newline at end of file

Reply via email to