Skip to content
This repository has been archived by the owner on Feb 7, 2020. It is now read-only.

Commit

Permalink
Fixed the rest of tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirlat committed Mar 21, 2018
1 parent 625fb2b commit e08bd46
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 59 deletions.
16 changes: 7 additions & 9 deletions dist/alpheios-data-models.js

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

2 changes: 1 addition & 1 deletion dist/alpheios-data-models.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "alpheios-data-models",
"version": "1.1.2",
"version": "1.1.3",
"description": "Alpheios Data Models",
"main": "dist/alpheios-data-models.js",
"directories": {
Expand Down
1 change: 1 addition & 0 deletions src/feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default class Feature {
this.languageID = languageID
this.allowedValues = allowedValues

// `_data` is an array
this._data = Feature.dataValuesFromInput(data)
this.sort()
}
Expand Down
6 changes: 2 additions & 4 deletions src/inflection_grouping_key.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ class InflectionGroupingKey {
* @returns {boolean} true if found, false if not
*/
hasFeatureValue (feature, value) {
for (let f of this[feature]) {
if (f.hasValue(value)) {
return true
}
if (this.hasOwnProperty(feature)) {
return this[feature].values.includes(value)
}
return false
}
Expand Down
9 changes: 4 additions & 5 deletions src/lexeme.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,16 @@ class Lexeme {
* @returns {Function} function which can be passed to Array.sort
*/
static getSortByTwoLemmaFeatures (primary, secondary) {
// TODO: Review and fix the logic for this
return (a, b) => {
if (a.lemma.features[primary] && b.lemma.features[primary]) {
if (a.lemma.features[primary].items[0].sortOrder < b.lemma.features[primary].items[0].sortOrder) {
if (a.lemma.features[primary][0].sortOrder < b.lemma.features[primary][0].sortOrder) {
return 1
} else if (a.lemma.features[primary].items[0].sortOrder > b.lemma.features[primary].items[0].sortOrder) {
} else if (a.lemma.features[primary][0].sortOrder > b.lemma.features[primary][0].sortOrder) {
return -1
} else if (a.lemma.features[secondary] && b.lemma.features[secondary]) {
if (a.lemma.features[secondary].items[0].sortOrder < b.lemma.features[secondary].items[0].sortOrder) {
if (a.lemma.features[secondary][0].sortOrder < b.lemma.features[secondary][0].sortOrder) {
return 1
} else if (a.lemma.features[secondary].items[0].sortOrder > b.lemma.features[secondary].items[0].sortOrder) {
} else if (a.lemma.features[secondary][0].sortOrder > b.lemma.features[secondary][0].sortOrder) {
return -1
} else if (a.lemma.features[secondary] && !b.lemma.features[secondary]) {
return -1
Expand Down
73 changes: 37 additions & 36 deletions tests/language_model.test.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,52 @@
/* eslint-env jest */
'use strict'
// import LanguageModelFactory from '../src/language_model_factory.js'
// import Inflection from '../src/inflection.js'
// import Feature from '../src/feature.js'
import * as Constants from '../src/constants.js'
import LanguageModelFactory from '../src/language_model_factory.js'
import Inflection from '../src/inflection.js'
import Feature from '../src/feature.js'

describe('Language Model object', () => {
test('groupForDisplay', () => {
// A fake test to match a requirement of test suite containing only one test
let something = true
expect(something).toBeTruthy()
})
// TODO: Enable after clearing a situation with grouping functions
/* test('groupForDisplay', () => {
let basemodel = LanguageModelFactory.getLanguageForCode('foo')
let one = new Inflection('nat', 'lat', 'urae', null, null)
let two = new Inflection('nat', 'lat', 'urae', null, null)
let three = new Inflection('nat', 'lat', 'urae', null, null)
let four = new Inflection('natur', 'lat', 'ae', null, null)
let five = new Inflection('natur', 'lat', 'ae', null, null)
let six = new Inflection('natur', 'lat', 'ae', null, null)

one.addFeature(new Feature(Feature.types.part, 'verb', 'lat', 3))
one.addFeature(new Feature(Feature.types.tense, 'present', 'lat'))
one.addFeature(new Feature(Feature.types.gender, 'feminine', 'lat'))
one.addFeature(new Feature(Feature.types.voice, 'active', 'lat'))
one.addFeature(new Feature(Feature.types.mood, 'indicative', 'lat'))
test('groupForDisplay', () => {
let basemodel = LanguageModelFactory.getLanguageModel(Constants.LANG_LATIN)
let one = new Inflection('nat', Constants.LANG_LATIN, 'urae', null, null)
let two = new Inflection('nat', Constants.LANG_LATIN, 'urae', null, null)
let three = new Inflection('nat', Constants.LANG_LATIN, 'urae', null, null)
let four = new Inflection('natur', Constants.LANG_LATIN, 'ae', null, null)
let five = new Inflection('natur', Constants.LANG_LATIN, 'ae', null, null)
let six = new Inflection('natur', Constants.LANG_LATIN, 'ae', null, null)

one.addFeature(new Feature(Feature.types.part, [['verb', 3]], Constants.LANG_LATIN))
one.addFeature(new Feature(Feature.types.tense, 'present', Constants.LANG_LATIN))
one.addFeature(new Feature(Feature.types.gender, 'feminine', Constants.LANG_LATIN))
one.addFeature(new Feature(Feature.types.voice, 'active', Constants.LANG_LATIN))
one.addFeature(new Feature(Feature.types.mood, 'indicative', Constants.LANG_LATIN))

two.addFeature(new Feature(Feature.types.part, 'verb', 'lat', 3))
two.addFeature(new Feature(Feature.types.tense, 'present', 'present', 'lat'))
two.addFeature(new Feature(Feature.types.gender, 'feminine', 'lat'))
two.addFeature(new Feature(Feature.types.voice, 'passive', 'lat'))
two.addFeature(new Feature(Feature.types.mood, 'indicative', 'lat'))
two.addFeature(new Feature(Feature.types.part, [['verb', 3]], Constants.LANG_LATIN))
two.addFeature(new Feature(Feature.types.tense, 'present', Constants.LANG_LATIN))
two.addFeature(new Feature(Feature.types.gender, 'feminine', Constants.LANG_LATIN))
two.addFeature(new Feature(Feature.types.voice, 'passive', Constants.LANG_LATIN))
two.addFeature(new Feature(Feature.types.mood, 'indicative', Constants.LANG_LATIN))

three.addFeature(new Feature(Feature.types.part, 'verb', 'lat', 3))
three.addFeature(new Feature(Feature.types.tense, 'future', 'lat'))
three.addFeature(new Feature(Feature.types.gender, 'masculine', 'lat'))
three.addFeature(new Feature(Feature.types.mood, 'subjunctive', 'lat'))
three.addFeature(new Feature(Feature.types.part, [['verb', 3]], Constants.LANG_LATIN))
three.addFeature(new Feature(Feature.types.tense, 'future', Constants.LANG_LATIN))
three.addFeature(new Feature(Feature.types.gender, 'masculine', Constants.LANG_LATIN))
three.addFeature(new Feature(Feature.types.mood, 'subjunctive', Constants.LANG_LATIN))

four.addFeature(new Feature(Feature.types.part, 'noun', 'lat', 5))
four.addFeature(new Feature(Feature.types.grmCase, 'nominative', 'lat', 5))
four.addFeature(new Feature(Feature.types.number, 'singular', 'lat'))
five.addFeature(new Feature(Feature.types.part, 'noun', 'lat', 5))
five.addFeature(new Feature(Feature.types.grmCase, 'accusative', 'lat', 5))
five.addFeature(new Feature(Feature.types.number, 'singular', 'lat'))
six.addFeature(new Feature(Feature.types.part, 'noun', 'lat', 5))
six.addFeature(new Feature(Feature.types.grmCase, 'accusative', 'lat', 5))
six.addFeature(new Feature(Feature.types.number, 'plural', 'lat'))
four.addFeature(new Feature(Feature.types.part, [['noun', 5]], Constants.LANG_LATIN))
four.addFeature(new Feature(Feature.types.grmCase, [['nominative', 5]], Constants.LANG_LATIN))
four.addFeature(new Feature(Feature.types.number, 'singular', Constants.LANG_LATIN))
five.addFeature(new Feature(Feature.types.part, [['noun', 5]], Constants.LANG_LATIN))
five.addFeature(new Feature(Feature.types.grmCase, [['accusative', 5]], Constants.LANG_LATIN))
five.addFeature(new Feature(Feature.types.number, 'singular', Constants.LANG_LATIN))
six.addFeature(new Feature(Feature.types.part, [['noun', 5]], Constants.LANG_LATIN))
six.addFeature(new Feature(Feature.types.grmCase, [['accusative', 5]], Constants.LANG_LATIN))
six.addFeature(new Feature(Feature.types.number, 'plural', Constants.LANG_LATIN))
let inflections = [one, two, three, four, five, six]
let grouped = basemodel.groupInflectionsForDisplay(inflections)
expect(grouped.length).toEqual(2)
Expand All @@ -68,5 +69,5 @@ describe('Language Model object', () => {
expect(active[0].inflections[0].groupingKey.hasFeatureValue(Feature.types.gender, 'feminine')).toBeTruthy()
expect(active[0].inflections[0].inflections.length).toEqual(1)
expect(active[0].inflections[0].inflections[0]).toEqual(one)
}) */
})
})
5 changes: 2 additions & 3 deletions tests/lexeme.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ describe('Lexeme object', () => {
})

test('Sorting on feature order', () => {
// TODO: fix later
/* let mockLexemeOne = {
let mockLexemeOne = {
lemma: {
features: {
freq: [ { sortOrder: 5 } ],
Expand All @@ -76,7 +75,7 @@ describe('Lexeme object', () => {
let sortFunc = Lexeme.getSortByTwoLemmaFeatures('freq', 'pofs')
expect(lexemes.sort(sortFunc)).toEqual([mockLexemeTwo, mockLexemeOne])
lexemes = [ mockLexemeTwo, mockLexemeThree ]
expect(lexemes.sort(sortFunc)).toEqual([mockLexemeTwo, mockLexemeThree]) */
expect(lexemes.sort(sortFunc)).toEqual([mockLexemeTwo, mockLexemeThree])
})

test('isPopulated', () => {
Expand Down

0 comments on commit e08bd46

Please sign in to comment.