-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parse templates in Wiktionary #88
Comments
There is (kind of) answer, but you wouldn't like it :( Infoboxer.wiktionary.api.expandtemplates.text('{{m|la|Russiānus}}').prop(:wikitext).response['wikitext']
# => <i class="Latn mention" lang="la">[[Russianus#Latin|Russiānus]]</i> ...unfortunately, to do so, you'll need the template source, and Infoboxer, somewhat dumbly, doesn't provide a way to do it. The best guess is to imitate it by recreating: class Infoboxer::Tree::Template
def source
[
"{{#{name}",
*unnamed_variables.map(&:text),
*named_variables.map { |v| "#{v.name}=#{v.text}"},
].join('|') + '}}'
end
end
wiktionary = Infoboxer.wiktionary
section = wiktionary.get("Russian").sections.first.sections("Etymology")
section.templates.map(&:source).each { |t|
puts t
puts wiktionary.api.expandtemplates.text(t).prop(:wikitext).response['wikitext']
} ...this will print
...but, unfortunately again, in extracting readable text from it you are on your own mostly. Though, Infoboxer's parser can provide a bit of help: section.templates.map(&:source).each { |t|
print "expanding `#{t}`: "
expanded = wiktionary.api.expandtemplates.text(t).prop(:wikitext).response['wikitext']
puts Infoboxer::Parser.inline(expanded).text
} output:
(yeah, those |
I wonder how do I use it to get the Wiktionary data. For example an Etymology section for "Russian".
How do I replace those templates like
{der:en|ML.|-}
with their real meaning to get:The text was updated successfully, but these errors were encountered: