1.0.0 • Published 2 years ago

wtf-plugin-summary v1.0.0

Weekly downloads
18
License
MIT
Repository
github
Last release
2 years ago

Tries to generate a small fragment of text (or 'clause') that describes a wikipedia article in english.

The process:

  • look for a {{short description}` template
  • grab and process the first-sentence of a wikipedia article
  • build a summary from a good category

Most-often it will find something of a reasonable length in the first-sentence.

if you want a even more confident fallback. you could use wtf-plugin-classify to output 'Politician', if this library finds nothing.

const wtf = require('wtf_wikipedia')
wtf.extend(require('wtf-plugin-summary'))
;(async () => {
  await wtf.fetch('Toronto Raptors').summary()
  // 'a Canadian professional basketball team'
  await wtf.fetch('Toronto Raptors').article()
  // 'they'
  await wtf.fetch('Toronto Raptors').tense()
  // 'present'
})()
<script src="https://unpkg.com/wtf_wikipedia"></script>
<script src="https://unpkg.com/wtf-plugin-summary"></script>
<script defer>
  wtf.plugin(window.wtfSummary)
  wtf.fetch('Elvis Presley').then((doc) => {
    console.log(doc.summary())
    // 'American singer and actor'
  })
</script>

The idea is that every output is a short, uncomplicated 'is-a' text, and can be treated grammatically like:

let copula = doc.tense() === 'past' ? 'was' : 'is'
return `${doc.title()} ${copula} ${doc.summary()}.`
// 'Wayne Gretzky is a Canadian ice hockey player.'

this plugin uses compromise for working with plaintext.

Options

let opts = {
  article: true, //remove leading 'a', 'the', etc
  template: true, // look for summary in {{short description}}
  sentence: true, //try to generate summary from first sentence
  category: true //try to convert a category into a summary
}
await wtf.fetch('Toronto Raptors').summary(opts)
// 'Canadian professional basketball team'

work-in-progress

MIT

1.0.0

2 years ago

0.3.2

2 years ago

0.3.1

2 years ago

0.3.0

3 years ago

0.2.0

4 years ago

0.1.0

4 years ago

0.0.1

4 years ago