Kaynağa Gözat

Merge pull request #2188 from visuddhinanda/agile

计算relation to 分类
visuddhinanda 1 yıl önce
ebeveyn
işleme
faa26745f1

+ 1 - 1
dashboard/src/components/general/NissayaCard.tsx

@@ -22,7 +22,7 @@ interface INissayaCardModal {
 export const NissayaCardPop = ({ text, trigger }: INissayaCardModal) => {
   return (
     <Popover
-      style={{ width: 600 }}
+      style={{ width: 700 }}
       content={<NissayaCardWidget text={text} cache={true} hideEditButton />}
       placement="bottom"
     >

+ 69 - 1
dashboard/src/components/general/NissayaCardTable.tsx

@@ -4,9 +4,48 @@ import { useEffect, useState } from "react";
 import { ArrowRightOutlined } from "@ant-design/icons";
 import Marked from "./Marked";
 import GrammarLookup from "../dict/GrammarLookup";
+import { useIntl } from "react-intl";
 
 const { Link } = Typography;
 
+const caseTags = [
+  { case: "fpp", tags: ["verb", "derivative", "passive-verb"] },
+  { case: "ger", tags: ["verb"] },
+  { case: "inf", tags: ["verb"] },
+  { case: "grd", tags: ["verb"] },
+  { case: "pp", tags: ["verb", "participle"] },
+  { case: "prp", tags: ["verb", "participle"] },
+  { case: "v", tags: ["verb"] },
+  { case: "v:ind", tags: ["verb"] },
+  { case: "vdn", tags: ["verb", "participle"] },
+];
+interface ITags {
+  tag: string;
+  count: number;
+}
+const getCaseTags = (input: string[]): ITags[] => {
+  let tagsMap = new Map<string, number>();
+  input.forEach((value: string) => {
+    const found = caseTags.find((value1) => value1.case === value);
+    if (found !== undefined) {
+      found.tags.forEach((value3) => {
+        const count = tagsMap.get(value3);
+        if (typeof count === "undefined") {
+          tagsMap.set(value3, 1);
+        } else {
+          tagsMap.set(value3, count + 1);
+        }
+      });
+    }
+  });
+  let tags: ITags[] = [];
+  tagsMap.forEach((value, key, map) => {
+    tags.push({ tag: key, count: value });
+  });
+  tags.sort((a, b) => b.count - a.count);
+  return tags;
+};
+
 const randomString = () =>
   lodash.times(20, () => lodash.random(35).toString(36)).join("");
 
@@ -23,6 +62,7 @@ interface DataType {
   key: string;
   relation: string;
   localRelation?: string;
+  tags?: ITags[];
   to?: IRelationNode;
   from?: IRelationNode;
   category?: { name: string; note: string; meaning: string };
@@ -43,6 +83,7 @@ interface IWidget {
   data?: INissayaRelation[];
 }
 const NissayaCardTableWidget = ({ data }: IWidget) => {
+  const intl = useIntl();
   let tableData: DataType[] = [];
 
   if (typeof data === "undefined") {
@@ -80,12 +121,20 @@ const NissayaCardTableWidget = ({ data }: IWidget) => {
               };
             });
           console.log("children", children);
+          let caseList: string[] = [];
+          children.forEach((value) => {
+            value.to?.case?.forEach((value1) => {
+              caseList.push(value1.case);
+            });
+          });
+          const tags = getCaseTags(caseList);
           newData.push({
             key: randomString(),
             relation: item.relation,
             localRelation: item.local_relation,
             from: item.from,
             to: item.to,
+            tags: tags,
             category: item.category,
             translation: item.local_ending,
             children: children.length > 1 ? [...children] : undefined,
@@ -178,12 +227,31 @@ const NissayaCardTableWidget = ({ data }: IWidget) => {
               return (
                 <Space>
                   <ArrowRightOutlined />
-                  {record.category?.meaning}
+                  {record.tags?.map((item, id) => {
+                    return (
+                      <Tag key={id}>
+                        {intl.formatMessage({
+                          id: `dict.case.category.${item.tag}`,
+                        })}
+                      </Tag>
+                    );
+                  })}
                 </Space>
               );
             }
           },
         },
+        {
+          title: "语法点",
+          dataIndex: "to",
+          key: "grammar",
+          width: "20%",
+          render: (value, record, index) => {
+            if (!record.isChildren) {
+              return record.category?.meaning;
+            }
+          },
+        },
         {
           title: "含义",
           dataIndex: "address",

+ 4 - 0
dashboard/src/locales/en-US/dict/index.ts

@@ -163,6 +163,10 @@ const items = {
   "dict.fields.type.comp.short.label": "comp.",
   "dict.fields.type.others.label": "others",
   "dict.fields.type.others.short.label": "others",
+  "dict.case.category.verb": "verb",
+  "dict.case.category.derivative": "derivative",
+  "dict.case.category.passive-verb": "passive-verb",
+  "dict.case.category.participle": "participle",
 };
 
 export default items;

+ 4 - 0
dashboard/src/locales/zh-Hans/dict/index.ts

@@ -163,6 +163,10 @@ const items = {
   "dict.fields.type.comp.short.label": "合",
   "dict.fields.type.others.label": "其他",
   "dict.fields.type.others.short.label": "其他",
+  "dict.case.category.verb": "动词",
+  "dict.case.category.derivative": "衍生词",
+  "dict.case.category.passive-verb": "被动动词",
+  "dict.case.category.participle": "分词",
 };
 
 export default items;