<commit_before>#!/usr/bin/env bash
# Script to create new FITeagle adapters
#
# More info:
#  - http://fiteagle.org
#
# Version 1.0.0
#
# Authors:
#  - <NAME> <<EMAIL>>
#
# Usage example:
#  ./createNewAdapter CoffeeMachine coffeemachine
#

# Enable dubugging
#set -o xtrace

# Exit on error. Append ||true if you expect an error.
# set -e is safer than #!/bin/bash -e because that is neutralised if
# someone runs your script like `bash yourscript.sh`
set -o errexit
set -o nounset

# Bash will remember & return the highest exitcode in a chain of pipes.
# This way you can catch the error in case mysqldump fails in `mysqldump |gzip`
set -o pipefail

# Environment variables and their defaults
LOG_LEVEL="${LOG_LEVEL:-6}" # 7 = debug -> 0 = emergency
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
class="${1:-}"
package="${2:-}"
rtype="${3:-}"
rspace="${4:-}"
src_class="Motor"
src_package="motor"
src_rtype="MotorGarage"
src_rspace="motorgarage"
dir_main="src/main/java/org/fiteagle/adapters/"
dir_test="src/test/java/org/fiteagle/adapters/"

if [ "" = "${package}" ]; then
  echo "USAGE: $0 <YourClassName> <yourpackagename> <ResourceType> <resourcenamespace>"
  echo "Example: $0 CoffeeMachine coffee Coffee coffee"
  exit 1
fi

[ -d "${package}" ] && (echo "FAIL: ${package} folder already exist"; exit 2;)
[[ "${class}" =~ [^a-zA-Z] ]] && (echo "FAIL: ${class} not a valid class name in Java"; exit 3;)
[[ "${package}" =~ [^a-z] ]] && (echo "FAIL: ${package} not a valid package name in Java"; exit 4;)

cp -r "${src_package}" "${package}"
cd "${package}" || (echo "FAIL: could not change dir" ; exit 5;)

sed -i.bak -e "s/${src_class}/${class}/g" pom.xml
sed -i.bak -e "s/${src_package}/${package}/g" pom.xml

mv ${dir_main}/${src_package} ${dir_main}/${package}
mv ${dir_test}/${src_package} ${dir_test}/${package}

find src -iname "${src_class}*.java"| xargs -I {} sh -c 'mv {} $(echo {}|sed "s/'${src_class}/${class}'/g")'
mv src/main/resources/ontologies/${src_package}.ttl src/main/resources/ontologies/${package}.ttl
sed -i.bak -e "s/${src_class}/${rtype}/g" src/main/resources/ontologies/${package}.ttl
sed -i.bak -e "s/${src_package}/${rspace}/g" src/main/resources/ontologies/${package}.ttl
find src -type f| xargs -I {} sh -c 'sed -i.bak -e "s/'${src_rspace}#${src_rtype}/${rspace}#${rtype}'/g" {}'
find src -type f| xargs -I {} sh -c 'sed -i.bak -e "s/'${src_class}/${class}'/g" {}'
find src -type f| xargs -I {} sh -c 'sed -i.bak -e "s/'${src_package}/${package}'/g" {}'
find . -iname "*.bak" -exec rm {} \;

mkdir -p ~/.fiteagle/
cat > ~/.fiteagle/${class}Garage.properties << EOL
{
  "adapterInstances": [
    {
      "componentID": "http://localhost/resource/CoffeemachineGarage-1"
    }
  ]
}
EOL


exit 0<commit_msg>fixing new adapter script [ci skip]<commit_after>#!/usr/bin/env bash
# Script to create new FITeagle adapters
#
# More info:
#  - http://fiteagle.org
#
# Version 1.0.0
#
# Authors:
#  - <NAME> <<EMAIL>>
#
# Usage example:
#  ./createNewAdapter CoffeeMachine Coffee
#

# Enable dubugging
#set -o xtrace

# Exit on error. Append ||true if you expect an error.
# set -e is safer than #!/bin/bash -e because that is neutralised if
# someone runs your script like `bash yourscript.sh`
set -o errexit
set -o nounset

# Bash will remember & return the highest exitcode in a chain of pipes.
# This way you can catch the error in case mysqldump fails in `mysqldump |gzip`
set -o pipefail

# Environment variables and their defaults
LOG_LEVEL="${LOG_LEVEL:-6}" # 7 = debug -> 0 = emergency
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__file="${__dir}/$(basename "${BASH_SOURCE[0]}")"
adapter="${1:-}"
resource="${2:-}"
adapter_small=$(echo ${adapter}|tr '[:upper:]' '[:lower:]')
resource_small=$(echo ${resource}|tr '[:upper:]' '[:lower:]')
src_adapter="MotorGarage"
src_resource="Motor"
src_adapter_small=$(echo ${src_adapter}|tr '[:upper:]' '[:lower:]')
src_resource_small=$(echo ${src_resource}|tr '[:upper:]' '[:lower:]')
dir_main="src/main/java/org/fiteagle/adapters/"
dir_test="src/test/java/org/fiteagle/adapters/"

if [ "" = "${resource}" ]; then
  echo "USAGE: $0 <ResourceAdapter> <Resource>"
  echo "Example: $0 CoffeeMachine Coffee"
  exit 1
fi

#echo "DEBUG From: ${src_adapter} ${src_adapter_small} ${src_resource} ${src_resource_small}"
#echo "DEBUG To: ${adapter} ${adapter_small} ${resource} ${resource_small}"

#todo: [[ "${adapter}" =~ [^A-Za-z] ]] && (echo "FAIL: ${adapter} not a valid class name in Java"; exit 2;)
#todo: [[ "${resource}" =~ [^A-Za-z] ]] && (echo "FAIL: ${resource} not a valid class name in Java"; exit 3;)
[ -d "${resource_small}" ] && (echo "FAIL: ${resource_small} folder already exist"; exit 4;)

cp -r "${src_resource_small}" "${resource_small}"
cd "${resource_small}" || (echo "FAIL: could not change dir" ; exit 5;)

sed -i.bak -e "s/${src_resource}/${resource}/g" pom.xml
sed -i.bak -e "s/${src_resource_small}/${resource_small}/g" pom.xml

mv ${dir_main}/${src_resource_small} ${dir_main}/${resource_small}
mv ${dir_test}/${src_resource_small} ${dir_test}/${resource_small}

find src -iname "${src_resource}*.java"| xargs -I {} sh -c 'mv {} $(echo {}|sed "s/'${src_resource}/${resource}'/g")'

mv src/main/resources/ontologies/${src_resource_small}.ttl src/main/resources/ontologies/${resource_small}.ttl
find src -type f| xargs -I {} sh -c 'sed -i.bak -e "s/'${src_adapter}/${adapter}'/g" {}'
find src -type f| xargs -I {} sh -c 'sed -i.bak -e "s/'${src_resource}/${resource}'/g" {}'
find src -type f| xargs -I {} sh -c 'sed -i.bak -e "s/'${src_adapter_small}/${adapter_small}'/g" {}'
find src -type f| xargs -I {} sh -c 'sed -i.bak -e "s/'${src_resource_small}/${resource_small}'/g" {}'

find . -iname "*.bak" -exec rm {} \;

mkdir -p ~/.fiteagle/
cat > ~/.fiteagle/${adapter}.properties << EOL
{
  "adapterInstances": [
    {
      "componentID": "http://localhost/resource/CoffeeMachine-1"
    }
  ]
}
EOL

exit 0
{'fraction_non_alphanumeric': 0.2110645431684828, 'fraction_numerical': 0.006705783738474434, 'mean_word_length': 4.4633699633699635, 'pattern_counts': {'":': 4, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3055412', 'n_tokens_mistral': 2270, 'n_tokens_neox': 2212, 'n_words': 594}