Skip to content

Commit

Permalink
Merge pull request #202 from alpheios-project/i75
Browse files Browse the repository at this point in the history
I75
  • Loading branch information
balmas authored Mar 19, 2020
2 parents 527b24d + a5cd20a commit 4231e02
Show file tree
Hide file tree
Showing 50 changed files with 75,852 additions and 75,665 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

495 changes: 258 additions & 237 deletions packages/client-adapters/dist/alpheios-client-adapters.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

365 changes: 193 additions & 172 deletions packages/client-adapters/dist/alpheios-client-adapters.node.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions packages/client-adapters/src/adapters/tufts/engine/morpheusgrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import * as Models from 'alpheios-data-models'

let data = new ImportData(Models.GreekLanguageModel, 'morpheusgrc') // eslint-disable-line prefer-const

// Morpheus uses 'irregular' as pofs for some pronouns, override with lemma
// the dictionary entry's conjugation if it's available
data.inflectionOverrides = {
[Models.Feature.types.part]: (i,ls) => i[Models.Feature.types.part].value === Models.Constants.TYPE_IRREGULAR && ls.filter( l => l.features[Models.Feature.types.part].value === Models.Constants.POFS_PRONOUN )
}
/*
Below are value conversion maps for each grammatical feature to be parsed.
Format:
Expand All @@ -17,4 +22,19 @@ data.addFeature(Models.Feature.types.gender).importer
data.addFeature(Models.Feature.types.declension).importer
.map('1st & 2nd', [[Models.Constants.ORD_1ST, 1], [Models.Constants.ORD_2ND, 2]])

data.setPropertyParser(function (propertyName, propertyValue, inputElem) {
let propertyValues = []
if (propertyName === 'decl') {
propertyValues = propertyValue.split('&').map((p) => p.trim())
} else if (propertyName === 'comp' && propertyValue === 'positive') {
propertyValues = []
} else if (propertyName === 'pofs' && propertyValue === 'irregular' &&
inputElem.hdwd && inputElem.hdwd.$ === 'τίς' ) {
propertyValues = [ Models.Constants.POFS_PRONOUN ]
} else {
propertyValues = [propertyValue]
}
return propertyValues
})

export default data
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ data.setMeaningParser(function (meaning, targetWord) {
return new Models.Definition(meaningText, lang, 'text/plain', targetWord)
})

data.setPropertyParser(function (propertyName, propertyValue) {
data.setPropertyParser(function (propertyName, propertyValue, inputElem) {
let propertyValues = []
if (propertyName === 'paradigm') {
// state has some extra "" around values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const data = new ImportData(Models.LatinLanguageModel, 'whitakerLat')

// Whitaker's has weird inflection data for conjugation, we prefer
// the dictionary entry's conjugation if it's available
data.inflectionOverrides = [Models.Feature.types.conjugation]
data.inflectionOverrides = { [Models.Feature.types.conjugation]: (i,ls) => true }

/*
Below are value conversion maps for each grammatical feature to be parsed.
Expand All @@ -25,7 +25,7 @@ data.addFeature(Models.Feature.types.gender).importer
data.addFeature(Models.Feature.types.tense).importer
.map('future_perfect', Models.Constants.TENSE_FUTURE_PERFECT)

data.setPropertyParser(function (propertyName, propertyValue) {
data.setPropertyParser(function (propertyName, propertyValue, inputElem) {
let propertyValues = []
if (propertyName === 'decl') {
propertyValues = propertyValue.split('&').map((p) => p.trim())
Expand Down
13 changes: 7 additions & 6 deletions packages/client-adapters/src/adapters/tufts/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ImportData {

// may be overridden by specific engine use via setPropertyParser - default just returns the property value
// as a list
this.parseProperty = function (propertyName, propertyValue) {
this.parseProperty = function (propertyName, propertyValue, inputElem) {
let propertyValues = []
if (propertyName === 'decl') {
propertyValues = propertyValue.split('&').map((p) => p.trim())
Expand Down Expand Up @@ -195,10 +195,10 @@ class ImportData {
if (Array.isArray(inputItem)) {
// There are multiple values of this feature
for (const e of inputItem) {
values.push(...this.parseProperty(inputName, e.$))
values.push(...this.parseProperty(inputName, e.$, inputElem))
}
} else {
values = this.parseProperty(inputName, inputItem.$)
values = this.parseProperty(inputName, inputItem.$, inputElem)
}
// `values` is always an array as an array is a return value of `parseProperty`
if (values.length > 0) {
Expand Down Expand Up @@ -233,11 +233,11 @@ class ImportData {
console.warn('Mutiple feature values with mismatching attribute value', inputElem)
}
featureName = e[attributeName]
values.push(...this.parseProperty(inputName, e.$))
values.push(...this.parseProperty(inputName, e.$, inputElem))
}
} else {
featureName = inputItem[attributeName]
values = this.parseProperty(inputName, inputItem.$)
values = this.parseProperty(inputName, inputItem.$, inputElem)
}
// `values` is always an array as an array is a return value of `parseProperty`
if (values.length > 0) {
Expand All @@ -257,7 +257,8 @@ class ImportData {
* @param {Lemma[]} lemmas the lemma objects
*/
overrideInflectionFeatureIfRequired (featureType, inflection, lemmas) {
if (this.inflectionOverrides.includes(featureType)) {
if (this.inflectionOverrides[featureType] &&
this.inflectionOverrides[featureType](inflection,lemmas)) {
for (const lemma of lemmas.filter(l => l.features[featureType])) {
inflection.addFeature(lemma.features[featureType])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class TransformAdapter {
for (const f of this.config.featuresArrayAll) {
try {
mappingData.mapFeature(inflection, inflectionJSON, ...f, this.config.allowUnknownValues)
mappingData.overrideInflectionFeatureIfRequired(f[1], inflection, lemmas)
mappingData.overrideInflectionFeatureIfRequired(Feature.types[f[1]], inflection, lemmas)
} catch (e) {
// quietly continue
}
Expand All @@ -216,7 +216,7 @@ class TransformAdapter {
for (const f of this.config.attributeBasedFeatures) {
try {
mappingData.mapFeatureByAttribute(inflection, inflectionJSON, ...f, this.config.allowUnknownValues)
mappingData.overrideInflectionFeatureIfRequired(f[1], inflection, lemmas)
mappingData.overrideInflectionFeatureIfRequired(Feature.types[f[1]], inflection, lemmas)
} catch (e) {
// quietly continue
}
Expand Down
21 changes: 21 additions & 0 deletions packages/client-adapters/tests/adapters/tufts/morpheusgrc.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-env jest */
import { Constants } from 'alpheios-data-models'
import Morpheus from '@clAdapters/adapters/tufts/engine/morpheusgrc'

describe('morpheusgrc.test.js', () => {

beforeEach(() => {
})
afterEach(() => {
jest.resetModules()
})
afterAll(() => {
jest.clearAllMocks()
})

it('1 Morpheusgrc Engine - sets pofs for irregular pronoun ti/s', () => {
let mockInput = { hdwd: { $: "τίς"} }
let parsed = Morpheus.parseProperty('pofs', 'irregular',mockInput)
expect(parsed).toEqual([Constants.POFS_PRONOUN])
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -468,4 +468,44 @@ describe('tufts-example.test.js', () => {
expect(homonym.lexemes[0].lemma.features.source.value).not.toEqual(expect.stringMatching(/from sedra.bethmardutho.org/))
})

it('24 TuftsExample - correct results for greek τίς', async () => {
let word = 'τίς'
let res = Fixture.getFixtureRes({
langCode: 'grc', adapter: 'tufts', word: word
})
let adapter = new AlpheiosTuftsAdapter({
category: 'morphology',
adapterName: 'tufts',
method: 'getHomonym',
sourceData: res
})
let homonym = await adapter.getHomonym(Constants.LANG_GREEK,word)
expect(homonym.lexemes.length).toEqual(2)
expect(homonym.lexemes[0].lemma.features['part of speech'].value).toEqual('pronoun')
expect(homonym.lexemes[1].lemma.features['part of speech'].value).toEqual('pronoun')
expect(homonym.lexemes[0].inflections[0]['part of speech'].value).toEqual("pronoun")
expect(homonym.lexemes[0].inflections[1]['part of speech'].value).toEqual("pronoun")
expect(homonym.lexemes[1].inflections[0]['part of speech'].value).toEqual("pronoun")
expect(homonym.lexemes[1].inflections[1]['part of speech'].value).toEqual("pronoun")
})

it('25 TuftsExample - correct results for greek τίνος', async () => {
let word = 'τίνος'
let res = Fixture.getFixtureRes({
langCode: 'grc', adapter: 'tufts', word: word
})
let adapter = new AlpheiosTuftsAdapter({
category: 'morphology',
adapterName: 'tufts',
method: 'getHomonym',
sourceData: res
})
let homonym = await adapter.getHomonym(Constants.LANG_GREEK,word)
expect(homonym.lexemes.length).toEqual(2)
expect(homonym.lexemes[0].lemma.features['part of speech'].value).toEqual('pronoun')
expect(homonym.lexemes[1].lemma.features['part of speech'].value).toEqual('pronoun')
expect(homonym.lexemes[0].inflections[0]['part of speech'].value).toEqual("pronoun")
expect(homonym.lexemes[1].inflections[0]['part of speech'].value).toEqual("pronoun")
})

})
Loading

0 comments on commit 4231e02

Please sign in to comment.