模糊谎言在https://en.wiktionary.org/wiki/faint的wiktionary
词源部分的wikitext是:
从{inh_enm_enm_faynt},{m_enm\enm\feynt弱;从{etyl fro}{m#fro\fro弱}},从{{etyl fro_feign}{m#fro薄弱}},{{m_m_fro feindre},{{m_fro feindre}},{{m_fro feindre}的过去分词,{{m_fro feindre},{{m_fro feindre},从{etyl la la en}},{{m_fro_fro feindre},{{m_fro feindre}的过去分词,{{m_fro feindre}},{{m_fro feindre}},{{m_fro feindre}}的过去分词,{{m_fro_fro feindre}}的过去分词,{{m_fro_fro feindre}}的过去分词,{{m\fro feindre}}的过去分词;假的;工作的疏忽},从{etyl la la enm}{m la enm}}触摸,处理,通常是形状,框架,形式,在思想、想象、构思、设计、设计}中的形式。
它包含各种形式的模板{{xyz\…}
我想解析它们并获得页面上显示的文本输出:
从中古英语费恩特(“弱;弱”),从旧法语昏倒,假装(“假装;疏忽;迟缓”),过去分词费因德尔,模糊(“假装;假;工作疏忽”),从拉丁语指(“触摸,处理,通常形式,形状,框架,形式,想象,构思,设计,设计,假装”)。
我从维基词典这里的免费转储中提取了大约10000条条目。
要做到这一点,我的想法是提取模板及其扩展(以某种形式)。为了探索可能性,我一直在使用mediawiki上的lua脚本工具。通过在模块的编辑页面上尝试调试控制台中的各种查询,如下所示:
https://en.wiktionary.org/w/index.php?title=Module:languages/print&action=edit
mw.log(p)
>> table
mw.logObject(p)
>> table#1 {
["code_to_name"] = function#1,
["name_to_code"] = function#2,
}
p.code_to_name("aaa")
>>
p.code_to_name("ab")
>>但是,我甚至不能正确地调用函数。p.code_to_name("aaa")不返回任何东西。
扩展词源部分模板的代码如下:https://en.wiktionary.org/w/index.php?title=Module:etymology/templates
如何正确调用此代码?有更简单的方法来实现我解析wikitext模板的目标吗?在mediawiki中是否有一些我可以调用的函数,比如“解析-wikitext(”text“)。如果是,我如何调用它?
发布于 2018-10-15 20:08:19
要在wikitext中展开模板(和其他内容),请使用frame.preprocess,它作为frame对象上的一个方法调用。若要获取frame对象,请使用mw.getCurrentFrame。例如,在控制台中键入= mw.getCurrentFrame():preprocess('{{l|en|word}}')以获得由{{l|en|word}}生成的wikitext。目前,这给了<span class="Latn" lang="en">[[word#English|word]]</span>。
您还可以在扩展模板操作中使用MediaWiki API ( https://en.wiktionary.org/w/api.php?action=expandtemplates&text={{l|en|word}})、特别咨商地位:扩展模板页面或JavaScript (如果您在浏览Wiktionary时打开浏览器控制台):
new mw.Api().get({
action: 'parse',
text: '{{l|en|word}}',
title: mw.config.values.wgPageName,
}).done(function (data) {
const wikitext = data.parse.text['*'];
if (wikitext)
console.log(wikitext);
});如果mw.api库尚未加载并得到一个TypeError ("mw.Api不是构造函数“):
mw.loader.using("mediawiki.api", function() {
// Use mw.Api here.
});因此,这些是一些扩展模板的方法。
https://stackoverflow.com/questions/52816628
复制相似问题