Skip to content

Commit

Permalink
Add zhangma
Browse files Browse the repository at this point in the history
  • Loading branch information
tansongchen committed Jul 22, 2024
1 parent 3fe7495 commit a854a40
Show file tree
Hide file tree
Showing 14 changed files with 1,160 additions and 76 deletions.
815 changes: 815 additions & 0 deletions examples/zhangma.yaml

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion spec/degenerator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ const hasroot = (a: RenderedGlyph, indices: number[], root: RenderedGlyph) => {
};

describe("degenerate cross tests", () => {
const {,,,,,,,,,,,,,,} =
const {,,,,,,,,,,,,,,, } =
renderedGlyphs as any;
const han = renderedGlyphs["\ue104"]!;
const mao3 = renderedGlyphs["\ue17d"]!;
it("says 天 has 大", () => {
expect(degenerate()).toEqual(degenerate(slice(, [1, 2, 3])));
});
Expand Down Expand Up @@ -125,6 +126,9 @@ describe("degenerate cross tests", () => {
it("says E104 has 夫", () => {
hasroot(han, [7, 8, 9, 10], );
});
it("says 龵 has 龵", () => {
hasroot(, [0, 1, 2], mao3);
});
});

describe("degenerate cross tests 2", () => {
Expand Down
5 changes: 3 additions & 2 deletions src/atoms/config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { atom } from "jotai";
import { atomFamily, atomWithStorage } from "jotai/utils";
import type { Analysis, Data, EncoderConfig } from "~/lib";
import type { Analysis, Data, EncoderConfig, Example } from "~/lib";
import {
defaultOptimization,
type Algebra,
type Config,
type Info,
defaultConfig,
examples,
} from "~/lib";
import { focusAtom } from "jotai-optics";
import { atomWithLocation } from "jotai-location";
Expand All @@ -22,7 +23,7 @@ export const idAtom = atom((get) => {
});

const configStorage = atomFamily((id: string) =>
atomWithStorage(id, defaultConfig),
atomWithStorage<Config>(id, examples[id as Example] ?? defaultConfig),
);

export const configAtom = atom(
Expand Down
8 changes: 8 additions & 0 deletions src/components/DetailEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ export default function DetailEditor({
}),
})),
},
{
value: "特殊",
label: "特殊",
children: [
{ value: "张码补码", label: "张码补码" },
{ value: "张码准码元", label: "张码准码元" },
],
},
];
return (
<Panel position="top-right">
Expand Down
21 changes: 13 additions & 8 deletions src/components/ResultDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type { SchemeWithData } from "~/lib";
const makeSorter = (selector: Selector) => {
return (a: SchemeWithData, b: SchemeWithData) => {
for (const sieve of selector) {
const [af, bf] = [a.data.get(sieve), b.data.get(sieve)];
const [af, bf] = [a.evaluation.get(sieve), b.evaluation.get(sieve)];
if (af === undefined && bf === undefined) return 0;
if (af === undefined) return -1;
if (bf === undefined) return 1;
Expand Down Expand Up @@ -47,10 +47,10 @@ export default function ResultDetail({
title: "拆分方式",
dataIndex: "sequence",
key: "sequence",
render: (_, { sequence }) => (
render: (_, { scheme }) => (
<Space>
{sequence.map((root, index) => (
<Element key={index}>{display(root)}</Element>
{scheme.map((root, index) => (
<Element key={index}>{display(map.get(root)!)}</Element>
))}
</Space>
),
Expand All @@ -62,8 +62,8 @@ export default function ResultDetail({
columns.push({
title: sieve,
key: sieve,
render: (_, { data }) => {
const value = data.get(sieve);
render: (_, { evaluation }) => {
const value = evaluation.get(sieve);
return (
<span>
{display && value ? display(value as number & number[]) : value}
Expand All @@ -76,10 +76,15 @@ export default function ResultDetail({
columns.push({
title: "操作",
key: "operations",
render: (_, { sequence }, index) => (
render: (_, { scheme }, index) => (
<Button
disabled={index === 0}
onClick={() => addCustomization(char, sequence)}
onClick={() =>
addCustomization(
char,
scheme.map((x) => map.get(x)!),
)
}
>
采用
</Button>
Expand Down
38 changes: 19 additions & 19 deletions src/lib/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ export const getComponentScheme = function (
return {
strokes: component.glyph.length,
sequence: [component.name],
full: [component.name],
corners: [0, 0, 0, 0],
operator: undefined,
};
const rootMap = new Map<number, string>(
component.glyph.map((stroke, index) => {
Expand All @@ -143,28 +145,22 @@ export const getComponentScheme = function (
if (selectResult instanceof Error) {
return selectResult;
}
const [bestScheme, schemeData] = selectResult;
const sequence = bestScheme.map((n) => rootMap.get(n)!);
const detail = bestScheme.map((n) => ({ name: rootMap.get(n)!, binary: n }));
const schemes = schemeData.map((v) => {
return {
scheme: v.scheme,
sequence: v.scheme.map((x) => rootMap.get(x)!),
data: v.evaluation,
};
});
const [best, schemes] = selectResult;
const sequence = best.scheme.map((n) => rootMap.get(n)!);
const corners = component.corners.map((corner) =>
bestScheme.findIndex(
best.scheme.findIndex(
(x) => x & (1 << (component.glyph.length - corner - 1)),
),
) as CornerSpecifier;
return {
sequence,
detail,
full: sequence,
strokes: component.glyph.length,
map: rootMap,
best,
schemes,
corners,
operator: undefined,
};
};

Expand All @@ -176,26 +172,30 @@ export type ComponentAnalysis =
| ComponentGenuineAnalysis;

export interface SchemeWithData {
sequence: string[];
scheme: number[];
data: Map<SieveName, number | number[]>;
evaluation: Map<SieveName, number | number[]>;
}

export interface CommonAnalysis {
sequence: string[];
full: string[];
corners: CornerSpecifier;
}

/**
* 部件本身是字根字,或者是由自定义部件拆分指定的无理拆分,无拆分细节
*/
export interface ComponentBasicAnalysis {
export interface ComponentBasicAnalysis extends CommonAnalysis {
strokes: number;
sequence: string[];
corners: CornerSpecifier;
operator: undefined;
}

/**
* 部件通过自动拆分算法分析得到的拆分结果的全部细节
*/
interface ComponentGenuineAnalysis extends ComponentBasicAnalysis {
detail: { name: string; binary: number }[];
export interface ComponentGenuineAnalysis extends ComponentBasicAnalysis {
map: Map<number, string>;
best: SchemeWithData;
schemes: SchemeWithData[];
}

Expand Down
Loading

0 comments on commit a854a40

Please sign in to comment.