Skip to content
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

Sections without intro texts #185

Closed
DanielSWolf opened this issue Sep 19, 2018 · 3 comments
Closed

Sections without intro texts #185

DanielSWolf opened this issue Sep 19, 2018 · 3 comments
Labels

Comments

@DanielSWolf
Copy link

Consider the following script:

var wtf = require("wtf_wikipedia");

const text = `
==English==

===Etymology===
{{suffix|abbreviate|ory|lang=en}}

===Pronunciation===
* {{a|GenAm}} {{IPA|/əˈbɹi.vi.əˌtɔɹ.i/|lang=en}}

===Adjective===
{{en-adj}}

# Serving or tending to [[abbreviate]]; [[shortening]]; [[abridging]]. {{defdate|Mid 19<sup>th</sup> century.}}<ref name=SOED>{{R:SOED5|page=3}}</ref>

====Translations====
{{trans-top|serving or tending to abbreviate; shortening; abridging}}
* Dutch: {{t+|nl|afkortend}}, {{t+|nl|verkortend}}
{{trans-mid}}
* Portuguese: {{t|pt|abreviatório}}, {{t|pt|abreviativo}}
{{trans-bottom}}

===References===
<references/>
`;

const document = wtf(text, { title: 'abbreviatory' });
console.log(JSON.stringify(document.json(), null, 2));

This document (which is taken from Wiktionary) has a single top-level section with the title "English". Nested within that top-level section are four second-level sections.

Here's the output:

{
  "title": "abbreviatory",
  "citations": [
    {
      "template": "citation",
      "type": "inline",
      "data": {},
      "inline": {
        "text": "{{R:SOED5|page=3}}"
      }
    }
  ],
  "sections": [
    {
      "title": "",
      "depth": 0,
      "sentences": [
        {
          "text": "==English=="
        }
      ]
    },
    {
      "title": "Etymology",
      "depth": 1,
      "sentences": [],
      "templates": [
        {
          "template": "suffix",
          "data": {
            "lang": "en"
          }
        }
      ]
    },
    {
      "title": "Pronunciation",
      "depth": 1,
      "sentences": [],
      "templates": [
        {
          "template": "ipa",
          "lang": null,
          "ipa": "/əˈbɹi.vi.əˌtɔɹ.i/lang=en"
        }
      ]
    },
    {
      "title": "Adjective",
      "depth": 1,
      "sentences": [
        {
          "text": "# Serving or tending to abbreviate; shortening; abridging.",
          "links": [
            {
              "page": "abbreviate"
            },
            {
              "page": "shortening"
            },
            {
              "page": "abridging"
            }
          ]
        }
      ],
      "templates": [
        {
          "template": "citation",
          "type": "inline",
          "data": {},
          "inline": {
            "text": "{{R:SOED5|page=3}}"
          }
        }
      ]
    },
    {
      "title": "Translations",
      "depth": 2,
      "sentences": [],
      "templates": [
        {
          "template": "t+",
          "data": [
            "nl",
            "afkortend"
          ]
        },
        {
          "template": "t+",
          "data": [
            "nl",
            "verkortend"
          ]
        }
      ],
      "tables": [
        [
          {
            "text": "Dutch: ,"
          },
          {
            "text": "Portuguese: abreviatório, abreviativo"
          }
        ]
      ]
    },
    {
      "title": "References",
      "depth": 1,
      "sentences": []
    }
  ]
}

Here's what strikes me as odd:

  • All sections and subsections are returned as a flat array. I would have expected the top-level array to contain only a single section. How do I get only the top-level sections for a document?
  • The title property for the first section is empty. Shouldn't that be "English"? In turn, its sentences property contains "text": "==English==".
@spencermountain
Copy link
Owner

hey Daniel, yeah you're correct about the mis-parsing of the section title. I'll check that out.
you can use the depth property to find sections of a specific level. There are also .children() .parent() and so on methods, please check out the api

I played around with the idea of nested-sections, but it got really messy.
will look at the ==english== issue asap
cheers

@spencermountain spencermountain changed the title Sections not parsed correctly? Sections without intro texts Sep 19, 2018
@DanielSWolf
Copy link
Author

Thanks for the clarification about nested sections. I'm looking forward to the fixed title parsing!

spencermountain added a commit that referenced this issue Sep 19, 2018
@spencermountain
Copy link
Owner

this ==English== bug is now fixed in 6.0.0
cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants