Skip to content

Commit

Permalink
#11: ontologia_regulam, MVP javascript regulam
Browse files Browse the repository at this point in the history
  • Loading branch information
fititnt committed Nov 29, 2021
1 parent 6b84314 commit 528b7a0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 79 deletions.
4 changes: 2 additions & 2 deletions bin/hxltmcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5234,7 +5234,7 @@ def est_validum_ad_regula(
# return list(regula_multipla.keys())
for item in regula_multipla:
regula_regex = re.compile(
r"{0}".format(item['existere']), re.IGNORECASE)
r"{0}".format(item['python']), re.IGNORECASE)
# if not bool(regula_regex.match(hxlhashtag)):
if not bool(regula_regex.search(hxlhashtag)):
return False
Expand Down Expand Up @@ -5266,7 +5266,7 @@ def quod_rem_ab_regula(
# return list(regula_multipla.keys())
for item in regula_multipla:
regula_regex = re.compile(
r"{0}".format(item['rem']), re.IGNORECASE)
r"{0}".format(item['python']), re.IGNORECASE)

rem = regula_regex.finditer(hxlhashtag)
if rem:
Expand Down
94 changes: 35 additions & 59 deletions docs/ontologia-regulam.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,46 @@
<body>
<p>Regula testum. Ad console.log</p>
<script>

/****** _[eng-Latn] Edit this section [eng-Latn]_ ******/
const debug = true
const hxltm_ontologia_archivum = "./ontologia/cor.hxltm.215.json"
const testum_regula_adhoc = ''
const testum_exemplum_adhoc = [
{
hxl: '#item+linguam'
}
// ,{
// hxl: '#meta+linguam+invalid',
// speciem: ''
// }
]
/****** _[eng-Latn] Edit this section [eng-Latn]_ ******/

const quod_exemplum = (ontologia, exemplum_adhoc) => {
let resultatum = ontologia.ontologia_regulam.__exemplum || []
if (exemplum_adhoc.length > 0) {
resultatum = resultatum.concat(exemplum_adhoc)
} else {
debug && console.log('quod_exemplum non exemplum_adhoc')
}

const quod_exemplum = (ontologia) => {
let resultatum = ontologia.ontologia_regulam.__exemplum
// Ad hoc exemplum
resultatum.push(
{ hxl: '#item+linguam' }
// { hxl: '#item+linguam', classem: 'xpto' }
)
return resultatum
}

const actionem_testum = (exemplum, regula) => {
debug && console.log('actionem_testum', regula)
const regula_regex = new RegExp(regula, "i");
let errorem = []
exemplum.forEach(element => {
debug && console.log('exemplum element', element)
debug && console.log('actionem_testum item', element)
result = regula_regex.exec(element.hxl)
// console.log('regex_basim6 v2', element, result.groups)
// element.forEach(el2 => {
// console.log(el2)
// })
// If exemplum defined values, check if are equal
Object.entries(element).forEach(([key, value]) => {
if (result.groups[key]) {
// console.log('compare', element[key], result.groups[key])
if (element[key] !== result.groups[key]) {
console.error(`[key !=] ${key} ; ${element[key]} ; ${result.groups[key]}`)
console.error(
`[key !=] ${key} ; ${element[key]} ; ${result.groups[key]}`)
}
}
// console.log(`${key}: ${value}`)
});
});
if (errorem.length > 0) {
Expand All @@ -55,56 +62,25 @@
}

const main = (ontologia) => {
const regulam = ontologia.ontologia_regulam.__exemplum
// rem = testum_rem(ontologia)
const rem2 = quod_exemplum(ontologia)

// regex_basim5 = new RegExp("^\#(?<divisionem>(item|meta)).+?(?<classem>(conceptum|linguam|terminum))", "i");
// // regex_basim5 = new RegExp("^\#(?<divisionem>(item|meta)).{1}?(?<classem>(conceptum|linguam|terminum))", "i");
// // regex_basim5 = new RegExp("^\#(?<divisionem>(item|meta)).{1}?(?<classem>(conceptum|linguam|terminum)).{1}?.*", "i");
// rem.forEach(element => {
// result = regex_basim5.exec(element) || { groups: {} }
// console.log('regex_basim5', element, result.groups)
// });
// console.log('')
// console.log('')
regex_basim6 = new RegExp("^\#(?<divisionem>(item|meta)).+?(?<classem>(conceptum|linguam|terminum))(?<speciem>.*)", "i");
// // regex_basim5 = new RegExp("^\#(?<divisionem>(item|meta)).{1}?(?<classem>(conceptum|linguam|terminum))", "i");
// // regex_basim5 = new RegExp("^\#(?<divisionem>(item|meta)).{1}?(?<classem>(conceptum|linguam|terminum)).{1}?.*", "i");
// rem.forEach(element => {
// result = regex_basim6.exec(element) || { groups: {} }
// console.log('regex_basim6', element, result.groups)
// });
// console.log('')
// console.log('')

rem2.forEach(element => {
result = regex_basim6.exec(element.hxl) || { groups: {} }
console.log('regex_basim6 v2', element, result.groups)
// element.forEach(el2 => {
// console.log(el2)
// })
// If exemplum defined values, check if are equal
Object.entries(element).forEach(([key, value]) => {
if (result.groups[key]) {
// console.log('compare', element[key], result.groups[key])
if (element[key] !== result.groups[key]) {
console.error(`[key !=] ${key} ; ${element[key]} ; ${result.groups[key]}`)
}
}
// console.log(`${key}: ${value}`)
});
});
const est_regula = testum_regula_adhoc || ontologia.ontologia_regulam._basim.javascript
const est_exemplum = quod_exemplum(ontologia, testum_exemplum_adhoc)
if (debug) {
console.log(`main
est_regula [${est_regula}]
testum_regula_adhoc [${testum_regula_adhoc}]
ontologia_regulam [${ontologia.ontologia_regulam._basim.javascript}]
`)
console.log('main est_exemplum', est_exemplum)
}

actionem_testum(quod_exemplum(ontologia), ontologia.ontologia_regulam._basim.javascript)
actionem_testum(est_exemplum, est_regula)

}

fetch(hxltm_ontologia_archivum)
.then(response => {
return response.json();
})
// .then(jsondata => console.log(jsondata));
.then(jsondata => main(jsondata));

</script>
Expand Down
36 changes: 18 additions & 18 deletions ontologia/cor.hxltm.215.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3026,71 +3026,71 @@ ontologia_regulam:

# abstractum, https://en.wiktionary.org/wiki/abstractus#Latin
abstractum:
existere: "^#meta"
python: "^#meta"

# classem, https://en.wiktionary.org/wiki/classis#Latin
conceptum_classem:
existere: '(^#item|^#meta)\+conceptum'
python: '(^#item|^#meta)\+conceptum'

# concrētum, https://en.wiktionary.org/wiki/concretus
concretum:
existere: "^#item"
python: "^#item"

# Glottocode, https://glottolog.org/
glotto:
# 'port1283' ad '+ig_port1283+'
rem: '(?<=ig_)([\w]{4}[\d]{4})'
python: '(?<=ig_)([\w]{4}[\d]{4})'

# basim, https://en.wiktionary.org/wiki/basis#Latin
hxltm_basim:
existere: '(^#item|^#meta)(\+conceptum|\+linguam|\+terminum)'
rem: '(^#item|^#meta)(\+conceptum|\+linguam|\+terminum)'
python: '(^#item|^#meta)(\+conceptum|\+linguam|\+terminum)'
# rem: '(^#item|^#meta)(\+conceptum|\+linguam|\+terminum)'

# HXL vacabularies, +v_(...)
hxl_v:
existere: '(\+v_[\w|\d]+)'
rem: '(?<=\+)(v_[\w|\d]+)'
# existere: '(\+v_[\w|\d]+)'
python: '(?<=\+)(v_[\w|\d]+)'

iso639_1:
# 'en' in '+i_en'
rem: '(?<=i_)([\w]{2})\+'
python: '(?<=i_)([\w]{2})\+'

iso639_3:
# 'eng' in '+i_eng'
rem: '(?<=i_)([\w]{3})\+'
python: '(?<=i_)([\w]{3})\+'

iso15924:
# ISO 15924: 'latn' in '+is_latn+'
rem: 'TODO'
python: 'TODO'

iso15924_a:
# ISO 15924: 'latn' in '+is_latn+'
rem: '(?<=is_)([\w]{4})'
python: '(?<=is_)([\w]{4})'

iso15924_n:
# ISO 15924: '215' in +is_215+
rem: '(?<=is_)([\d]{3})'
python: '(?<=is_)([\d]{3})'

linguam_classem:
existere: '(^#item|^#meta)\+linguam'
python: '(^#item|^#meta)\+linguam'

# explicitum, https://en.wiktionary.org/wiki/implicitus#Latin
# implicitum, https://en.wiktionary.org/wiki/explicitus#Latin
# The bare minimum to be considered linguan is i_www+i_Wwww or i_www+i_nnn
linguam_basim_explicitum:
existere: '(\+i_([\w]{2}))([\w]{4}[\d]{4})?.*(\+is_[\w]{4}|\+is_[\d]{3}){1}' # needs more test
python: '(\+i_([\w]{2}))([\w]{4}[\d]{4})?.*(\+is_[\w]{4}|\+is_[\d]{3}){1}' # needs more test
# existere: '(\+is_([\w]{4})|([\d]{3}))'

# Implicitly language, value present as value on another column
linguam_basim_implicitum_de:
existere: '(\+de_linguam_fontem|\+de_linguam_objectivum|\+de_linguam)'
python: '(\+de_linguam_fontem|\+de_linguam_objectivum|\+de_linguam)'

# Implicitly language, this column have values from equivalent de_linguam*
linguam_basim_implicitum_est:
existere: '(\+est_linguam_fontem|\+est_linguam_objectivum|\+est_linguam)'
python: '(\+est_linguam_fontem|\+est_linguam_objectivum|\+est_linguam)'

terminum_classem:
existere: '(^#item|^#meta)\+terminum'
python: '(^#item|^#meta)\+terminum'

### Example test cases
#item+conceptum
Expand Down

0 comments on commit 528b7a0

Please sign in to comment.