Parsing 如何解析Wiktionary API?

Parsing 如何解析Wiktionary API?,parsing,wikimedia,wiktionary,Parsing,Wikimedia,Wiktionary,缺少演示如何解析Wiktionary API响应的在线资源,如下所示: 基本上我想要的只是英文的定义,但是回复格式太奇怪了,以至于这个词的所有内容都被混淆成一个不可分割的大团块 是否有一种API方法可以获得实际JSON格式的响应,其中英文定义只是一个JSON键 我是否必须求助于正则表达式模式才能做到这一点,这会是什么样子 最后,为什么API设计人员会返回这样的数据?我想判断一下,说他们不知道自己在做什么,但肯定有原因 使用extracts属性获取html版本 https://en.wiktion

缺少演示如何解析Wiktionary API响应的在线资源,如下所示:

基本上我想要的只是英文的定义,但是回复格式太奇怪了,以至于这个词的所有内容都被混淆成一个不可分割的大团块

  • 是否有一种API方法可以获得实际JSON格式的响应,其中英文定义只是一个JSON键
  • 我是否必须求助于正则表达式模式才能做到这一点,这会是什么样子
  • 最后,为什么API设计人员会返回这样的数据?我想判断一下,说他们不知道自己在做什么,但肯定有原因

  • 使用
    extracts
    属性获取html版本


    https://en.wiktionary.org/w/api.php?titles=cloud&action=query&prop=extracts&format=json

    为什么API没有将页面分解为定义,一个显而易见的答案是,它是一个通用的mediawiki API,而不是Wiktional API,对页面的结构一无所知(这只是一组遵循维基贡献者的约定,而不是一个正式指定的机器可解析标准)。因为我不隶属于维基(但是在我们的项目中已经分析了它们的数据),我只能假设,结构的原因是,它们使用了一个普通的MyaWiKi作为基础,不提供一个“字典式"结构。在我们的项目中,我们使用组合
    字符串#indexOf
    #子字符串
    等和一组正则表达式解析数据库转储。可怕的代码和维护噩梦。看起来是解析wiki文本的好地方。决定wiki语法树如何映射到字典定义的最后一步s将取决于你。有很多人的经验,他们是如何做到这一点的。可能重复的
    {
        "query": {
            "pages": {
                "40915": {
                    "pageid": 40915,
                    "ns": 0,
                    "title": "reluctant",
                    "revisions": [
                        {
                            "contentformat": "text/x-wiki",
                            "contentmodel": "wikitext",
                            "*": "==English==\n\n===Etymology===\nFrom {{etyl|la|en}} {{term|lang=la|reluctans}}, present participle of {{term|reluctare}}, {{term|reluctari||to struggle against, oppose, resist}}, from {{term|re-||back}} + {{term|luctari||to struggle}}.\n\n===Pronunciation===\n* {{IPA|/ɹɪˈlʌktənt/}}\n* {{audio|en-us-reluctant.ogg|Audio (US)}}\n\n===Adjective===\n{{en-adj}}\n\n# {{context|now|_|rare|lang=en}} [[opposing|Opposing]]; offering [[resistance]] (to).\n#* '''1819''', Lord Byron, ''Don Juan'', II.108:\n#*: There, breathless, with his digging nails he clung / Fast to the sand, lest the returning wave, / From whose '''reluctant''' roar his life he wrung, / Should suck him back to her insatiate grave [...].\n#* '''2008''', Kern Alexander et al., ''The World Trade Organization and Trade in Services'', p. 222:\n#*: They are '''reluctant''' to the inclusion of a necessity test, especially of a horizontal nature, and emphasize, instead, the importance of procedural disciplines [...].\n# Not [[wanting]] to take some [[action]]; [[unwilling]].\n#: ''She was '''reluctant''' to lend him the money''\n\n====Synonyms====\n* [[unwilling]], [[disinclined]]\n\n====Translations====\n{{trans-top|not wanting to take some action}}\n* Chinese: \n*: Mandarin: {{t|cmn|不情願|sc=Hani}}, {{t+|cmn|不情愿|tr=bùqíngyuàn|sc=Hani}}\n* Czech: {{t|cs|neochotný}}, {{t|cs|zdráhající}} se\n* Dutch: {{t+|nl|aarzelend}}\n* Finnish: {{t+|fi|haluton}}, {{t+|fi|vastahakoinen}}\n* French: {{t+|fr|réservé}},  {{t+|fr|réfractaire}},  {{t+|fr|rétif}}\n* German: {{t|de|zögernd}}\n* Hungarian: {{t|hu|kelletlen}}\n* Indonesian: {{t+|id|enggan}}\n* Interlingua: [[reluctante]]\n* Italian: {{t+|it|riluttante}}\n{{trans-mid}}\n* Latin: {{t|la|invītus}}\n* Manx: {{t|gv|neuarryltagh}}, {{t|gv|neuwooiagh}}\n* Maori: {{t|mi|whakawhēuaua}}, {{t|mi|manauhea}}\n* Polish: [[niechętny]]\n* Romanian: reticent, precaut, {{t|ro|prevăzător}}\n* Russian: {{t+|ru|неохотный|tr=neoxótnyj}}\n* Scots: {{t|sco|sweer}}, {{t|sco|sweirt}}, {{t|sco|laith}}\n* Scottish Gaelic: {{t|gd|aindeònach}}, {{t|gd|leisg}}\n* Spanish: {{t+|es|renuente}}, {{t|es|reacio}}\n* Swedish: {{t|sv|motvillig}}\n{{trans-bottom}}\n\n====Related terms====\n* [[reluctance]]\n* [[reluctantly]]\n\n===External links===\n* {{R:Webster 1913}}\n* {{R:Century 1911}}\n* {{R:OneLook}}\n\n[[ca:reluctant]]\n[[cy:reluctant]]\n[[et:reluctant]]\n[[el:reluctant]]\n[[es:reluctant]]\n[[fr:reluctant]]\n[[ko:reluctant]]\n[[io:reluctant]]\n[[kn:reluctant]]\n[[ku:reluctant]]\n[[hu:reluctant]]\n[[mg:reluctant]]\n[[ml:reluctant]]\n[[my:reluctant]]\n[[nl:reluctant]]\n[[pl:reluctant]]\n[[pt:reluctant]]\n[[simple:reluctant]]\n[[fi:reluctant]]\n[[sv:reluctant]]\n[[ta:reluctant]]\n[[te:reluctant]]\n[[th:reluctant]]\n[[vi:reluctant]]\n[[zh:reluctant]]"
                        }
                    ]
                }
            }
        }
    }