kanasimi / wikiapi

JavaScript MediaWiki API for node.js
https://kanasimi.github.io/wikiapi/
BSD 3-Clause "New" or "Revised" License
50 stars 6 forks source link

[Suggestion]: Merge this project. #67

Closed MarketingPip closed 11 months ago

MarketingPip commented 1 year ago

Hey @kanasimi -

Don't mean to dismiss your project by any means. Looks very cool! But I think this might be of interest - merging the functions from this (and possible improvements) into this project here.

Cheers! πŸ‘

kanasimi commented 1 year ago

Thank you for your suggestion. It seems that we are both working hard to improve the usability of wikitext. My goal is to edit various elements easily and use .toString() to restore the original text. After considering, I adopted Array and added all the additional attributes and functions in various properties. And wtf_wikipedia mainly uses JSON as the storage structure, and it seems that it has not yet implemented the .toString() function. I can’t say that my implementation is better. I just took a look, but I found that there is a big conflict between our data structures now.

MarketingPip commented 1 year ago

@kanasimi - I think you should dive into the library. Almost positive there is a feature that you are describing.

Example:

import wtf from 'wtf_wikipedia'
let str = `[[Greater_Boston|Boston]]'s [[Fenway_Park|baseball field]] has a {{convert|37|ft}} wall. <ref>Field of our Fathers: By Richard Johnson</ref>`
wtf(str).text()
// "Boston's baseball field has a 37ft wall."

Assuming this is what you are describing?

kanasimi commented 1 year ago

For example, I can do this:

    /** {Array} parsed page content */
    const parsed = CeL.wiki.parser(page_data).parse();
    parsed.each('Template:Artwork', function(token) {
        token.push('wikidata=Q27964733');
    });
    return parsed.toString();

(via here)

Perhaps you could show the wtf_wikipedia method of changing wikitext elements?

MarketingPip commented 1 year ago

@kanasimi - I do believe you are meaning parsing info boxes from Wiki Text (or any parts of Wiki - correct)? If so, that's exactly WTF_Wikipedia does. See here

Example (infobox parsed via a WikiTemplate):

import wtf from 'wtf_wikipedia'

let doc = await wtf.fetch('Toronto Raptors')
let coach = doc.infobox().get('coach')
coach.text() //'Nick Nurse'

Correct me if I am wrong.

kanasimi commented 1 year ago

Well, I created this library to make it easier for robots to edit. For example:

const wikitext = `aa {{Artwork|title=A}} bb {{Artwork|title=B}} cc`;
/** {Array} parsed page content */
const parsed = CeL.wiki.parser(wikitext).parse();
parsed.each('Template:Artwork', function(token) {
    token.push('wikidata=Q27964733');
});
console.assert(parsed.toString()
 === 'aa {{Artwork|title=A|wikidata=Q27964733}} bb {{Artwork|title=B|wikidata=Q27964733}} cc');

For the code you've shown, here's a counterpart with the same functionality.

const Wikiapi = require('wikiapi');
const wiki = new Wikiapi('en');

(async () => {

const page_data = await wiki.page('Toronto Raptors');
/** {Array} parsed page content */
const parsed = CeL.wiki.parser(page_data).parse();
parsed.each('Template', function(template_token) {
    if (/^Infobox /.test(template_token.name)) {
        console.log(template_token.parameters.coach);
    }
});

})();
MarketingPip commented 1 year ago

@kanasimi - I would assume it would be a benefit to community + this project + wtf_wikipedia.

  1. You can possibly create a plugin to make edits.
  2. I think it would benefit both from parsing templates (being a hard thing to do - the community would gain support by one project working towards properly parsing wikipedia)
  3. It would make a all-in-one go to Wikipedia tool. (Parser, editor & large community - of diverse backgrounds ❀️)

Just a food for thought! I am not a official contributor of wtf. Tho I have found myself contributing to Spencer's projects lately as they are awesome tools. (Not dissing on this tool either - just thinking of community as a whole).

kanasimi commented 1 year ago

It would be nice if we could. I just find the design and data structure of the two to be very different, which makes it difficult to merge the two unless the code is rewritten.

MarketingPip commented 1 year ago

@kanasimi - I suggest opening an issue and mentioning Spencer. And see if he has any suggestions! πŸ‘

kanasimi commented 1 year ago

Sure. Maybe @spencermountain can respond directly in this thread.

spencermountain commented 1 year ago

Wow this project is so cool- yeah, I've always wanted to be able to mutate the page and then call .toString() - nice work @kanasimi !! Yeah, i agree the projects are different. Ive tried turning the json back into wikitext but the process is lossy. Some ordering, for example gets lost. Whitespace too. Ive always wondered how bots mutate a page cleanly, and i think the answer is that they usually just append, or make a minimal regex replacement. This library is really cool - i'll start sending people here, who are asking for this feature at wtf. Let me know if i can help, in any way. Cheers

hugolpz commented 11 months ago

It would be nice if we could. I just find the design and data structure of the two to be very different, which makes it difficult to merge the two unless the code is rewritten.

I think this issue could be closed.

For most project it is too complex to do a merge. Each project will make its time.

Also, I'm pretty sure Kanasimi would be a great asset on any js projet :3