Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions src/models/Language.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import isGlottoCode from '../utilities/types/isGlottoCode.js';
import isISOCode from '../utilities/types/isISO.js';
import Model from '../core/Model.js';
import MultiLangString from './MultiLangString.js';
import Tags from './Tags.js';

/**
* Validates a language abbreviation. Throws a type error if the input is not a valid abbreviation.
Expand Down Expand Up @@ -54,6 +55,7 @@ function validateISOCode(input) {
* @prop {String} glottolog - The Glottocode for this language
* @prop {String} iso - The ISO 639-3 code for this language
* @prop {models.MultiLangString} name - The name of this language
* @prop {models.Tags} tags - The tags for this language
* @prop {String} type - "Language"
*/
class Language extends Model {
Expand All @@ -65,18 +67,20 @@ class Language extends Model {
* @param {String} [data.glottolog] The Glottolog Code for this language.
* @param {String} [data.iso] The ISO 639-3 code for this language.
* @param {Map|Object|String} [data.name] The name of this language. May be a string if English, an Object formatted as a [MultiLangString]{@link https://format.digitallinguistics.io/schemas/MultiLangString.html}, or a Map of language tags => transcriptions.
* @param {Map|Object} [data.tags] A Map or Object of tags for this Language, formatted as a [DLx Tags object]{@link https://format.digitallinguistics.io/schemas/Tags.html}.
*/
constructor(data = {}) {

super(data);

// Property Definitions

Model.defineModelProp(this, `name`, MultiLangString);
Model.defineTypeProp(this, `Language`);
Model.defineValidatedProp(this, `abbreviation`, validateAbbreviation);
Model.defineValidatedProp(this, `glottolog`, validateGlottoCode);
Model.defineValidatedProp(this, `iso`, validateISOCode);
Model.defineTypeProp(this, `Language`);
Model.defineModelProp(this, `name`, MultiLangString);
Model.defineModelProp(this, `tags`, Tags);

// Initialization

Expand Down
27 changes: 24 additions & 3 deletions src/models/Language.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,28 @@
import chai from 'chai';
import { Language, MultiLangString } from './index.js';

chai.should();
const should = chai.should();

describe(`Language`, () => {

it(`class: Language`, () => {
Language.name.should.equal(`Language`);
});

it(`instantiates with no data`, () => {

const lang = new Language;

should.not.exist(lang.abbreviation);
should.not.exist(lang.glottolog);
should.not.exist(lang.iso);
should.not.exist(lang.tags);

lang.type.should.equal(`Language`);
lang.name.should.be.instanceOf(MultiLangString);

});

it(`abbreviation`, () => {
const lang = new Language;
(() => { lang.abbreviation = undefined; }).should.not.throw();
Expand All @@ -22,9 +36,14 @@ describe(`Language`, () => {
});

it(`custom property`, () => {

const lang = new Language;
(() => { lang.deleted = true; }).should.not.throw();
lang.deleted.should.equal(true);

const l = new Language({ customProperty: true });
l.customProperty.should.be.true;

});

it(`glottolog`, () => {
Expand All @@ -44,12 +63,14 @@ describe(`Language`, () => {
});

it(`name`, () => {

const lang = new Language({ name: { eng: `Chitimacha` } });

lang.name.should.be.instanceOf(MultiLangString);
lang.name.get(`eng`).should.equal(`Chitimacha`);
});

it(`tags`, () => {
const lang = new Language({ tags: { position: `final` } });
lang.tags.get(`position`).should.equal(`final`);
});

it(`type`, () => {
Expand Down
7 changes: 6 additions & 1 deletion src/models/MultiLangString.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import chai from 'chai';
import Model from '../core/Model.js';
import MultiLangString from './MultiLangString.js';

const should = chai.should();
chai.should();

const modelName = `MultiLangString`;

Expand All @@ -21,6 +21,11 @@ describe(modelName, () => {

describe(`data`, () => {

it(`no data`, () => {
const mls = new MultiLangString;
mls.type.should.equal(`MultiLangString`);
});

it(`String`, () => {
const data = `hello`;
const mls = new MultiLangString(data);
Expand Down
1 change: 1 addition & 0 deletions src/models/Tags.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe(`Tags`, () => {
const tags = new Tags;
tags.should.be.instanceOf(Map);
tags.size.should.equal(0);
tags.type.should.equal(`Tags`);
});

it(`throws with bad data`, () => {
Expand Down
10 changes: 7 additions & 3 deletions src/models/Text.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
import Model from '../core/Model.js';
import MultiLangString from './MultiLangString.js';
import Tags from './Tags.js';
import Utterance from './Utterance.js';

/**
* A class representing a linguistic text, formatted according to the [DLx Data Format for a language]{@link https://format.digitallinguistics.io/schemas/Text.html}
* @memberof models
* @extends core.Model
* @prop {models.Tags} tags - The tags for this text
* @prop {models.MultiLangString} title - The title of this text
* @prop {core.Collection} utterances - An array of utterances in this text
*/
class Text extends Model {

/**
* Create a new Text
* @param {Object} [data={}] The data to use for this Text. Data should be formatted according to the [DLx Data Format's guidelines for Text data]{@link https://format.digitallinguistics.io/schemas/Text.html}.
* @param {Object} [data={}] The data for this text, formatted as a [DLx Text object]{@link https://format.digitallinguistics.io/schemas/Text.html}.
* @param {Map|Object} [data.tags] The tags for this text, formatted as a [DLx Tags object]{@link https://format.digitallinguistics.io/schemas/Tags.html}.
*/
constructor(data = {}) {

super(data);

Model.defineArrayProp(this, `utterances`, Utterance);
Model.defineModelProp(this, `title`, MultiLangString);
Model.defineModelProp(this, `tags`, Tags);
Model.defineTypeProp(this, `Text`);
Model.defineModelProp(this, `title`, MultiLangString);
Model.defineArrayProp(this, `utterances`, Utterance);

Object.assign(this, data);

Expand Down
15 changes: 15 additions & 0 deletions src/models/Text.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import chai from 'chai';
import Collection from '../core/Collection.js';
import MultiLangString from './MultiLangString.js';
import Text from './Text.js';

const should = chai.should();

describe(`Text`, () => {

it(`class: Text`, () => {
Expand All @@ -12,11 +15,23 @@ describe(`Text`, () => {

const text = new Text;

should.not.exist(text.tags);
text.title.should.be.instanceOf(MultiLangString);
text.type.should.equal(`Text`);
text.utterances.should.be.instanceOf(Collection);

});

it(`custom property`, () => {
const text = new Text({ customProperty: true });
text.customProperty.should.be.true;
});

it(`tags`, () => {
const text = new Text({ tags: { position: `final` } });
text.tags.get(`position`).should.equal(`final`);
});

it(`title`, () => {

const text = new Text({
Expand Down
4 changes: 3 additions & 1 deletion src/models/Utterance.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Model from '../core/Model.js';
import MultiLangString from './MultiLangString.js';
import Tags from './Tags.js';
import Transcription from './Transcription.js';
import Word from './Word.js';

Expand All @@ -22,11 +23,12 @@ class Utterance extends Model {

super();

Model.defineModelProp(this, `tags`, Tags);
Model.defineModelProp(this, `transcript`, Transcription);
Model.defineModelProp(this, `transcription`, Transcription);
Model.defineModelProp(this, `translation`, MultiLangString);
Model.defineArrayProp(this, `words`, Word);
Model.defineTypeProp(this, `Utterance`);
Model.defineArrayProp(this, `words`, Word);

Object.assign(this, data);

Expand Down
22 changes: 16 additions & 6 deletions src/models/Utterance.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import chai from 'chai';
import Collection from '../core/Collection.js';
import MultiLangString from './MultiLangString.js';
import Transcription from './Transcription.js';
import Utterance from './Utterance.js';
Expand All @@ -13,6 +14,7 @@ describe(`Utterance`, () => {

const utterance = new Utterance;

should.not.exist(utterance.tags);
should.not.exist(utterance.transcript);

utterance.transcription.should.be.instanceOf(Transcription);
Expand All @@ -21,15 +23,26 @@ describe(`Utterance`, () => {
utterance.translation.should.be.instanceOf(MultiLangString);
utterance.translation.size.should.equal(0);

utterance.type.should.equal(`Utterance`);

utterance.words.should.be.instanceOf(Collection);

});

it(`transcript`, () => {
it(`custom property`, () => {
const utterance = new Utterance({ customProperty: true });
utterance.customProperty.should.be.true;
});

const utterance = new Utterance({ transcript: testData });
it(`tags`, () => {
const utterance = new Utterance({ tags: { position: `final` } });
utterance.tags.get(`position`).should.equal(`final`);
});

it(`transcript`, () => {
const utterance = new Utterance({ transcript: testData });
utterance.transcript.should.be.instanceOf(Transcription);
utterance.transcript.get(`eng`).should.equal(testData.eng);

});

it(`transcription`, () => {
Expand All @@ -39,12 +52,9 @@ describe(`Utterance`, () => {
});

it(`translation`, () => {

const utterance = new Utterance({ translation: testData });

utterance.translation.should.be.instanceOf(MultiLangString);
utterance.translation.get(`eng`).should.equal(testData.eng);

});

it(`type`, () => {
Expand Down
2 changes: 2 additions & 0 deletions src/models/Word.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Model from '../core/Model.js';
import MultiLangString from './MultiLangString.js';
import Tags from './Tags.js';
import Transcription from './Transcription.js';

/**
Expand All @@ -25,6 +26,7 @@ class Word extends Model {
Model.defineModelProp(this, `analysis`, Transcription);
Model.defineModelProp(this, `gloss`, MultiLangString);
Model.defineModelProp(this, `literal`, MultiLangString);
Model.defineModelProp(this, `tags`, Tags);
Model.defineModelProp(this, `transcription`, Transcription);
Model.defineModelProp(this, `translation`, MultiLangString);
Model.defineTypeProp(this, `Word`);
Expand Down
20 changes: 10 additions & 10 deletions src/models/Word.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,45 +13,45 @@ describe(`Word`, () => {
const word = new Word;
should.not.exist(word.analysis);
should.not.exist(word.literal);
should.not.exist(word.tags);
word.transcription.should.be.instanceOf(Transcription);
word.transcription.size.should.equal(0);
should.not.exist(word.translation);
word.type.should.equal(`Word`);
});

it(`analysis`, () => {

const word = new Word({ analysis: testData });

word.analysis.should.be.instanceOf(Transcription);
word.analysis.get(`eng`).should.equal(testData.eng);
});

it(`custom property`, () => {
const word = new Word({ customProperty: true });
word.customProperty.should.be.true;
});

it(`literal`, () => {

const word = new Word({ literal: testData });

word.literal.should.be.instanceOf(MultiLangString);
word.literal.get(`eng`).should.equal(testData.eng);
});

it(`tags`, () => {
const word = new Word({ tags: { position: `final` } });
word.tags.get(`position`).should.equal(`final`);
});

it(`transcription`, () => {

const word = new Word({ transcription: testData });

word.transcription.should.be.instanceOf(Transcription);
word.transcription.get(`eng`).should.equal(testData.eng);

});

it(`translation`, () => {

const word = new Word({ translation: testData });

word.translation.should.be.instanceOf(MultiLangString);
word.translation.get(`eng`).should.equal(testData.eng);

});

it(`type`, () => {
Expand Down