Remove 'mock data' word entries, replace with smaller initial data
This commit is contained in:
parent
f19f2d5601
commit
e88ebee7c8
File diff suppressed because one or more lines are too long
@ -1,156 +0,0 @@
|
|||||||
import { parseWiktionaryData } from "../model/parseWiktionaryData";
|
|
||||||
import {
|
|
||||||
Category,
|
|
||||||
Expression,
|
|
||||||
ExpressionSet,
|
|
||||||
ExpressionToCategory,
|
|
||||||
ExpressionToExpressionSet,
|
|
||||||
} from "../model/types";
|
|
||||||
import { KiviRaw } from "./kivi";
|
|
||||||
import { PuhuaRaw } from "./puhua";
|
|
||||||
|
|
||||||
interface RawExpressionDataItem {
|
|
||||||
prompt: string;
|
|
||||||
data: string;
|
|
||||||
}
|
|
||||||
const RawExpressionData: RawExpressionDataItem[] = [
|
|
||||||
["kivi", KiviRaw],
|
|
||||||
["puhua", PuhuaRaw],
|
|
||||||
].map(([prompt, data]) => ({
|
|
||||||
prompt,
|
|
||||||
data,
|
|
||||||
}));
|
|
||||||
|
|
||||||
interface RawExpressionSetItem {
|
|
||||||
name: string;
|
|
||||||
description: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const RawExpressionSetData: RawExpressionSetItem[] = [
|
|
||||||
["daily", "New expressions and poorly remembered expressions"],
|
|
||||||
["weekly", "Expressions to be reviewed at the end of the week"],
|
|
||||||
["monthly", "Expressions to be reviewed at the end of the month"],
|
|
||||||
["yearly", "Expressions to be reviewed at the end of the year"],
|
|
||||||
["ancient", "Expressions here should be memorized by now"],
|
|
||||||
].map(([name, description]) => ({ name, description }));
|
|
||||||
|
|
||||||
const RawCategories: string[] = [
|
|
||||||
"noun",
|
|
||||||
"verb",
|
|
||||||
"adjective",
|
|
||||||
"adverb",
|
|
||||||
"determiner",
|
|
||||||
"article",
|
|
||||||
"preposition",
|
|
||||||
"conjunction",
|
|
||||||
"proper noun",
|
|
||||||
"letter",
|
|
||||||
"character",
|
|
||||||
"phrase",
|
|
||||||
"proverb",
|
|
||||||
"idiom",
|
|
||||||
"symbol",
|
|
||||||
"syllable",
|
|
||||||
"numeral",
|
|
||||||
"initialism",
|
|
||||||
"interjection",
|
|
||||||
"definitions",
|
|
||||||
"pronoun",
|
|
||||||
"particle",
|
|
||||||
"predicative",
|
|
||||||
"participle",
|
|
||||||
"suffix",
|
|
||||||
];
|
|
||||||
|
|
||||||
interface MockData {
|
|
||||||
// Tables
|
|
||||||
categories: Category[];
|
|
||||||
expressions: Expression[];
|
|
||||||
expression_sets: ExpressionSet[];
|
|
||||||
|
|
||||||
// Relationships
|
|
||||||
expression_to_category: ExpressionToCategory[];
|
|
||||||
expression_to_expression_set: ExpressionToExpressionSet[];
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ParseRawDataArgs {
|
|
||||||
raw_category_data: string[];
|
|
||||||
raw_expression_data: RawExpressionDataItem[];
|
|
||||||
raw_expression_set_data: RawExpressionSetItem[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export function parseRawData({
|
|
||||||
raw_category_data,
|
|
||||||
raw_expression_data,
|
|
||||||
raw_expression_set_data,
|
|
||||||
}: ParseRawDataArgs): MockData {
|
|
||||||
const categories: Category[] = raw_category_data.map((name) => ({
|
|
||||||
name,
|
|
||||||
description: name,
|
|
||||||
}));
|
|
||||||
|
|
||||||
const expression_sets: ExpressionSet[] = raw_expression_set_data.map(
|
|
||||||
({ name, description }) => ({
|
|
||||||
name,
|
|
||||||
description,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const expressions: Expression[] = [];
|
|
||||||
const expression_to_category: ExpressionToCategory[] = [];
|
|
||||||
const expression_to_expression_set: ExpressionToExpressionSet[] = [];
|
|
||||||
for (const { prompt, data } of raw_expression_data) {
|
|
||||||
console.log("Parsing", { prompt, data });
|
|
||||||
const expression = parseWiktionaryData(prompt, data);
|
|
||||||
if (!expression) continue;
|
|
||||||
|
|
||||||
expressions.push(expression);
|
|
||||||
const expression_id = expressions.length;
|
|
||||||
/*
|
|
||||||
expression_to_category.push(
|
|
||||||
matchExpressionAndCategory({
|
|
||||||
expression_id,
|
|
||||||
category_name,
|
|
||||||
categories,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
expression_to_expression_set.push({
|
|
||||||
expression_id,
|
|
||||||
expression_set_id: 1,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
categories,
|
|
||||||
expressions,
|
|
||||||
expression_sets,
|
|
||||||
expression_to_category,
|
|
||||||
expression_to_expression_set,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
interface MatchExpressionAndCategoryParams {
|
|
||||||
expression_id: number;
|
|
||||||
category_name: string;
|
|
||||||
categories: Category[];
|
|
||||||
}
|
|
||||||
|
|
||||||
function matchExpressionAndCategory({
|
|
||||||
expression_id,
|
|
||||||
category_name,
|
|
||||||
categories,
|
|
||||||
}: MatchExpressionAndCategoryParams): ExpressionToCategory {
|
|
||||||
const category_id =
|
|
||||||
categories.findIndex(({ name }) => name === category_name) + 1;
|
|
||||||
return {
|
|
||||||
category_id,
|
|
||||||
expression_id,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export const MockData = parseRawData({
|
|
||||||
raw_category_data: RawCategories,
|
|
||||||
raw_expression_data: RawExpressionData,
|
|
||||||
raw_expression_set_data: RawExpressionSetData,
|
|
||||||
});
|
|
File diff suppressed because one or more lines are too long
@ -1,4 +1,4 @@
|
|||||||
import { MockData } from "../mock/mock-data";
|
import { initialData } from "./initial-data";
|
||||||
import Dexie, { Table } from "dexie";
|
import Dexie, { Table } from "dexie";
|
||||||
import {
|
import {
|
||||||
Category,
|
Category,
|
||||||
@ -42,7 +42,7 @@ database.on("populate", (transaction) => {
|
|||||||
categories,
|
categories,
|
||||||
expression_to_expression_set,
|
expression_to_expression_set,
|
||||||
expression_to_category,
|
expression_to_category,
|
||||||
} = MockData;
|
} = initialData;
|
||||||
db.expressions.bulkAdd(expressions);
|
db.expressions.bulkAdd(expressions);
|
||||||
db.expression_sets.bulkAdd(expression_sets);
|
db.expression_sets.bulkAdd(expression_sets);
|
||||||
db.categories.bulkAdd(categories);
|
db.categories.bulkAdd(categories);
|
||||||
|
86
src/model/initial-data.ts
Normal file
86
src/model/initial-data.ts
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
import {
|
||||||
|
Category,
|
||||||
|
Expression,
|
||||||
|
ExpressionSet,
|
||||||
|
ExpressionToCategory,
|
||||||
|
ExpressionToExpressionSet,
|
||||||
|
} from "./types";
|
||||||
|
|
||||||
|
const RawExpressionData: Expression[] = [];
|
||||||
|
|
||||||
|
const RawExpressionSetData: ExpressionSet[] = [
|
||||||
|
["daily", "New expressions and poorly remembered expressions"],
|
||||||
|
["weekly", "Expressions to be reviewed at the end of the week"],
|
||||||
|
["monthly", "Expressions to be reviewed at the end of the month"],
|
||||||
|
["yearly", "Expressions to be reviewed at the end of the year"],
|
||||||
|
["ancient", "Expressions here should be memorized by now"],
|
||||||
|
].map(([name, description]) => ({ name, description }));
|
||||||
|
|
||||||
|
// TODO replace with data source, data type or other category like wiktionary, species, math?
|
||||||
|
const RawCategories: Category[] = [
|
||||||
|
"noun",
|
||||||
|
"verb",
|
||||||
|
"adjective",
|
||||||
|
"adverb",
|
||||||
|
"determiner",
|
||||||
|
"article",
|
||||||
|
"preposition",
|
||||||
|
"conjunction",
|
||||||
|
"proper noun",
|
||||||
|
"letter",
|
||||||
|
"character",
|
||||||
|
"phrase",
|
||||||
|
"proverb",
|
||||||
|
"idiom",
|
||||||
|
"symbol",
|
||||||
|
"syllable",
|
||||||
|
"numeral",
|
||||||
|
"initialism",
|
||||||
|
"interjection",
|
||||||
|
"definitions",
|
||||||
|
"pronoun",
|
||||||
|
"particle",
|
||||||
|
"predicative",
|
||||||
|
"participle",
|
||||||
|
"suffix",
|
||||||
|
].map((name) => ({ name, description: name }));
|
||||||
|
|
||||||
|
interface InitialData {
|
||||||
|
// Tables
|
||||||
|
categories: Category[];
|
||||||
|
expressions: Expression[];
|
||||||
|
expression_sets: ExpressionSet[];
|
||||||
|
|
||||||
|
// Relationships
|
||||||
|
expression_to_category: ExpressionToCategory[];
|
||||||
|
expression_to_expression_set: ExpressionToExpressionSet[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ParseRawDataArgs {
|
||||||
|
raw_category_data: Category[];
|
||||||
|
raw_expression_data: Expression[];
|
||||||
|
raw_expression_set_data: ExpressionSet[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function parseRawData({
|
||||||
|
raw_category_data,
|
||||||
|
raw_expression_data,
|
||||||
|
raw_expression_set_data,
|
||||||
|
}: ParseRawDataArgs): InitialData {
|
||||||
|
const expression_to_category: ExpressionToCategory[] = [];
|
||||||
|
const expression_to_expression_set: ExpressionToExpressionSet[] = [];
|
||||||
|
|
||||||
|
return {
|
||||||
|
categories: raw_category_data,
|
||||||
|
expressions: raw_expression_data,
|
||||||
|
expression_sets: raw_expression_set_data,
|
||||||
|
expression_to_category,
|
||||||
|
expression_to_expression_set,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const initialData = parseRawData({
|
||||||
|
raw_category_data: RawCategories,
|
||||||
|
raw_expression_data: RawExpressionData,
|
||||||
|
raw_expression_set_data: RawExpressionSetData,
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user