Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F60930012
runEye.sh
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, May 3, 11:15
Size
4 KB
Mime Type
text/x-shellscript
Expires
Sun, May 5, 11:15 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
17441766
Attached To
rNIETZSCHEONTOLOGIE Nietzsche-Ontologie
runEye.sh
View Options
#!/bin/bash
#start:special option edit {{{1
##--edit: special option edit
if [[ `echo $@ | grep '[-][-]edit'` != "" ]];then
if [[ -e ~/bin/bin.vim ]];then
vi -s ~/bin/bin.vim $0
else
edit $0
fi
exit $?
fi
#end:special option edit 1}}}
function usage () { #{{{1
test -n "$2" && echo $2
echo "Usage: `basename $0` machineReasoningDir [--ontology=ontology.ttl] raw-data.ttl|raw-dataDir [output.ttl|outputDir]"
grep '^##[-]' $0
exit $1
}
##--help,-h: show help
if [[ `echo $@ | grep '\(^[-]h$\|[-][-]help\)'` != "" ]];then
usage 0
fi
#1}}}
function initVars () { #{{{1
rootDir=$(echo $1 | sed 's_/$__')
test -d $rootDir || usage 2 "ERROR: ${rootDir} does not exist!"
if [[ -z $(whereis $EYE | awk '{ print $2 }') || ! -e $(whereis $EYE | awk '{ print $2 }') ]];then
EYE=$(find / -name 'eye.sh' 2>/dev/null | head -1)
test -z "$EYE" && usage 2 "Please install EYE by josd, see ${rootDir}/EYE_INSTALL_info"
fi
shift 1
if [[ -n $(echo $@ | grep '^[-][-]ontology=\S*\.ttl') ]];then
ontology=$(echo $@ | sed 's/\(.*--ontology=\)\(\S*\.ttl\)\(.*\)/\2/')
test -e $ontology || ontology=""
shift 1
fi
data=$1
output=$2
for data_item in ${data};do
test -e $data_item || usage 2 "ERROR: data-file ${data} does not exist!"
done
} #1}}}
function update_directory_content () { #{{{1
now=$(date +%s)
for directory in $@;do
if [[ -e ${directory}/sources.txt ]];then
for url in $(cat ${directory}/sources.txt);do
local_file=${directory}/$(basename $url)
if [[ ! -e ${local_file} || $(($now - $(stat -c %Y ${local_file}))) -gt 86400 ]];then
wget -O $local_file $url
fi
done
fi
done
} #1}}}
function create_execution_string () { #{{{1
executionString="--nope --traditional"
local run_on_joined_data=$1
if [[ "$run_on_joined_data" != true ]];then
update_directory_content ${rootDir}/ontologies ${rootDir}/external-rules ${rootDir}/generic-rules
fi
if [[ -n "$ontology" && -e $ontology ]];then
if [[ -e ${rootDir}/ontologies/$(basename $ontology) ]];then
cp $ontology ${rootDir}/ontologies/
else
executionString="${executionString} $ontology"
fi
fi
for local_ontology in $(ls ${rootDir}/ontologies/*.ttl 2>/dev/null);do
executionString="${executionString} $local_ontology"
done
executionString="${executionString} $data"
rules=""
if [[ "$run_on_joined_data" != true ]];then
rules="$(ls ${rootDir}/external-rules/*.n3 ${rootDir}/project-rules/*.n3 ${rootDir}/generic-rules/*.n3 2>/dev/null)"
else
rules="$(ls ${rootDir}/*joined_data/*.n3 2>/dev/null)"
fi
executionString="${executionString} $rules"
if [[ -e $(ls ${rootDir}/*query.n3 2>/dev/null| head -1 ) ]];then
if [[ -n $(grep '^[^#]\+kb:retract' $rules | head -1) && -e ${rootDir}/filter_query.n3 ]];then
executionString="${executionString} --query ${rootDir}/filter_query.n3"
else
executionString="${executionString} --query ${rootDir}/query.n3"
fi
fi
} #1}}}
function runEye () { #{{{1
local run_on_joined_data=$1
create_execution_string $run_on_joined_data
if [[ -n "$output" && -d $output ]];then
tmp_output=$output
if [[ -n $(echo $data | grep '\s') ]];then
output="${output}/$(date +%F)"
for data_item in $data;do
output="${output}_$(basename ${data_item/.ttl} | sed 's/DATA//')"
done
output="${output}.ttl"
else
output=${output}/$(date +%F)_$(basename ${data})
fi
fi
if [[ -n "$output" && -e $output ]];then
test -d bak/ || mkdir bak
cp $output bak/
fi
if [[ -n $(echo $output | grep '\.ttl$') ]];then
echo "# Execution date" $(date) > $output
$EYE $executionString >> $output
elif [[ -z "$output" ]];then
$EYE $executionString
else
echo "# Execution date" $(date) > $output
$EYE $executionString |cwm >> $output
fi
joined_data="${joined_data} $output"
output=$tmp_output
} #1}}}
if [[ -z "$2" ]];then
usage 2 "ERROR: needs at least 2 arguments"
fi
EYE=eye.sh
rootDir=""
ontology=""
data=""
output=""
executionString=""
initVars $@
if [[ -d $data ]];then
data_dir=$data
joined_data=""
for data in $(ls ${data_dir}/*DATA.ttl);do
runEye false
done
if [[ -n "$(find $rootDir -regex '.*_joined_data' -type d | head -1)" ]];then
output="$(echo $joined_data | awk '{ print $1 }' | xargs dirname)/$(date +%F)"
for file in $joined_data;do
output="${output}$(echo $file | xargs basename | sed 's/\([0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}\)\(.*\)\(\.ttl\)/\2/' | sed 's/_DATA//')"
done
output="${output}.ttl"
data=$joined_data
runEye true
if [[ -e ${output} ]];then
for file in $data;do
rm $file
done
fi
fi
else
runEye false
fi
Event Timeline
Log In to Comment