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

replaceExternalLinks removes wrong closing square bracket with nested internal link #55

Closed
spyysalo opened this issue Mar 11, 2016 · 2 comments

Comments

@spyysalo
Copy link
Contributor

To replicate:

replaceExternalLinks('[http://example.org [[internal|link]] text]')

result:

'[[internal|link] text]'

expected:

'[[internal|link]] text'

This causes further breakage in downstream processing.

Internal links within external links appear with some frequency in the raw Wikipedia data and are reasonably resolved by MediaWiki. For example,

[http://www.palaeos.org/Proteobacteria Proteobacteria information from [[Palaeos]].]

occurs in the source for https://en.wikipedia.org/wiki/Proteobacteria#External_links .

(Found when trying to fix #54, which previously masked this issue.)

@spyysalo
Copy link
Contributor Author

I looked at this a bit more, and the issue appears to be this regex: https://github.com/attardi/wikiextractor/blob/master/WikiExtractor.py#L2039, in particular the part

([^\]\x00-\x08\x0a-\x1F]*?)\]

which eats left square brackets (only ] appears in the negated character class) and terminates on the first closing bracket.

It should be possible to fix with the following pattern (here writingBADCHARS for \x00-\x08\x0a-\x1F for readability)

((?:[^][BADCHARS]|\[\[[^][BADCHARS]*\]\])*?)\]

Would you consider a pull request implementing this?

@attardi
Copy link
Owner

attardi commented Mar 12, 2016

Alternatively one may look for the first ] which is not followed by another ], i.e.:

'](?!])'

Please try it and let me know.

spyysalo added a commit to spyysalo/wikiextractor that referenced this issue Mar 12, 2016
See attardi/wikiextractor/issues/attardi#55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants