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

Issue 42 #46

Merged
merged 7 commits into from
Aug 27, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
622 changes: 318 additions & 304 deletions dist/alpheios-data-models.js

Large diffs are not rendered by default.

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 dist/alpheios-data-models.min.js

Large diffs are not rendered by default.

622 changes: 318 additions & 304 deletions dist/alpheios-data-models.node.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

31,426 changes: 15,689 additions & 15,737 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@
"homepage": "https://github.com/alpheios-project/data-models#readme",
"devDependencies": {
"alpheios-node-build": "github:alpheios-project/node-build",
"babel-jest": "^23.4.0",
"babel-preset-env": "^1.7.0",
"coveralls": "^3.0.2",
"eslint": "^5.4.0",
"intl-messageformat": "^2.1.0",
"jest": "^23.4.0",
"jest-fetch-mock": "1.6.5",
Expand Down
9 changes: 7 additions & 2 deletions src/feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,17 @@ export default class Feature {
/**
* Compares a feature's values to another feature's values for sorting
* @param {Feature} otherFeature the feature to compare this feature's values to
* @return {integer} >=1 if this feature should be sorted first, 0 if they are equal and -1 if this feature should be sorted second
* @return {integer} < 1 if this feature should be sorted first, 0 if they are equal and -1 if this feature should be sorted second
*/
compareTo (otherFeature) {
// the data values are sorted upon construction and insertion so we only should need to look at the first values
// feature sortOrders are descending (i.e. 5 sorts higher than 1)
return otherFeature._data[0].sortOrder - this._data[0].sortOrder
if (otherFeature) {
return otherFeature._data[0].sortOrder - this._data[0].sortOrder
} else {
// if the other feature isn't defined, this one sorts first
return -1
}
}

get items () {
Expand Down
9 changes: 9 additions & 0 deletions src/lexeme.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class Lexeme {
}

this.lemma = lemma
this.altLemmas = []
this.inflections = []
inflections.forEach(i => { this.addInflection(i) })
this.meaning = meaning || new DefinitionSet(this.lemma.word, this.lemma.languageID)
Expand All @@ -57,6 +58,14 @@ class Lexeme {
this.inflections.push(inflection)
}

/**
* add an alternative lemma to the lexeme
* @param {Lemma} lemma
*/
addAltLemma (lemma) {
this.altLemmas.push(lemma)
}

/**
* test to see if a lexeme is populated with meaningful data
* Returns true if any of these are true:
Expand Down
5 changes: 5 additions & 0 deletions tests/feature.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ describe('feature.test.js', () => {
b = new Feature(Feature.types.frequency, [['higher', 2]], Constants.LANG_GREEK)
expect(a.compareTo(b)).toBeLessThan(0)
expect([a, b].sort((a, b) => a.compareTo(b))).toEqual([a, b])

// expects null values to be handled
a = new Feature(Feature.types.frequency, [['lower', 1], ['highest', 3]], Constants.LANG_GREEK)
b = null
expect(a.compareTo(b)).toBeLessThan(0)
})

it('7 Feature - check get types, isAllowedType, defaultSortOrder, joinSeparator, defaultImporterName', () => {
Expand Down
7 changes: 7 additions & 0 deletions tests/lexeme.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,4 +267,11 @@ describe('lexeme.test.js', () => {
expect(lex.disambiguated).toBeFalsy()
expect(lex.inflections).toEqual([inflection1, inflection2])
})
it('8 Lexeme - adds alternate Lemmas', () => {
let lemma2 = new Lemma('word', 'grc')
let lex = new Lexeme(lemma, [])
expect(lex.altLemmas.length).toEqual(0)
lex.addAltLemma(lemma2)
expect(lex.altLemmas).toEqual([lemma2])
})
})