New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

text-annotator

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

text-annotator - npm Package Compare versions

Comparing version 0.8.0 to 0.8.1

2

package.json
{
"name": "text-annotator",
"version": "0.8.0",
"version": "0.8.1",
"description": "A JavaScript library for locating and annotating plain text in HTML",

@@ -5,0 +5,0 @@ "main": "build/text-annotator.js",

@@ -5,4 +5,5 @@ # text-annotator

1. **Search**: Search for a piece of plain text in the HTML; if finding it, store its location identified by an index and then return the index for later annotation
2. **Annotate**: Annotate the found text given its index
It can be seen that in order to annotate a piece of text, two steps, **search** and **annotate**, are taken. The idea of decomposing the annotation process into the two steps is to allow more flexibility, e.g., the user can search for all pieces of text first, and then annotate (some of) them later when required (e.g., when clicking a button). There is also a function combining the two steps, as can be seen in the Basic usage section.
2. **Annotate**: Annotate the found text given its index<br />
It can be seen that in order to annotate a piece of text, two steps, **search** and **annotate**, are taken. The idea of decomposing the annotation process into the two steps is to allow more flexibility, e.g., the user can search for all pieces of text first, and then annotate (some of) them later when required (e.g., when clicking a button). There is also a function combining the two steps, as can be seen in the **An example of the usage** section.<br />
*text-annotator* can be used in the browser or the Node.js server.

@@ -26,3 +27,3 @@ ## Import

// create an instance of TextAnnotator
// containerId is the id of the HTML container
// content is the HTML string within which a piece of text can be annotated
var annotator = new TextAnnotator({content: document.getElementById('content').innerHTML})

@@ -42,7 +43,7 @@

// search all occurances of 'Europe PMC' in the HTML
// search for all occurances of 'Europe PMC' in the HTML
var highlightIndexes = annotator.searchAll('Europe PMC')
// highlightIndexes = [1, 2]
// annotate all found occurances of 'Europe PMC' given their indexes
// annotate all the found occurances of 'Europe PMC' given their indexes
if (highlightIndexes.length) {

@@ -54,3 +55,3 @@ document.getElementById('content').innerHTML = annotator.highlightAll(highlightIndexes)

// search and annotate 'a partner of PubMed Central'
// search for and then annotate 'a partner of PubMed Central'
document.getElementById('content').innerHTML = annotator.searchAndHighlight('a partner of PubMed Central').content

@@ -69,3 +70,3 @@ // searchAndHighlight returns { content, highlightIndex }

## Constructor options
*new TextAnnotator(**options**)*
#### new TextAnnotator(*options*)
| Prop | Type | Description |

@@ -76,4 +77,4 @@ | ---- | ---- | ---- |

## Search options
*search(str, **options**)*<br />
*searchAll(str, **options**)*
#### search(str, *options*)
#### searchAll(str, *options*)
| Prop | Type | Description |

@@ -85,5 +86,5 @@ | ---- | ---- | ---- |

## Annotate options
*highlight(highlightIndex, **options**)*<br />
*highlightAll(highlightIndexes, **options**)*<br />
*unhighlight(highlightIndex, **options**)*
#### highlight(highlightIndex, *options*)
#### highlightAll(highlightIndexes, *options*)
#### unhighlight(highlightIndex, *options*)
| Prop | Type | Description |

@@ -90,0 +91,0 @@ | ---- | ---- | ---- |

@@ -453,43 +453,2 @@ import getSentences from './ext/sbd'

// // step 4: find the sentence that includes the most similar str
// let bestResult = null
// let mostPossibleSentence = null
// filteredSentences.forEach((sentence, index) => {
// let result = TextAnnotator.getBestSubstring(
// sentence.raw,
// str,
// sbThreshold,
// lenRatio,
// caseSensitive
// )
// if (result.similarity) {
// sbThreshold = result.similarity
// bestResult = result
// mostPossibleSentence = sentence
// } else if (index !== filteredSentences.length - 1) {
// // combine two sentences to reduce the inaccuracy of sentenizing text
// result = TextAnnotator.getBestSubstring(
// sentence.raw + filteredSentences[index + 1].raw,
// str,
// sbThreshold,
// lenRatio,
// caseSensitive
// )
// if (result.similarity) {
// sbThreshold = result.similarity
// bestResult = result
// mostPossibleSentence = filteredSentences[index]
// }
// }
// })
// // step 5: if such sentence is found, derive and return the location of the most similar str
// if (bestResult) {
// let index = mostPossibleSentence.index
// highlightIndex =
// this.highlights.push({
// loc: [index + bestResult.loc[0], index + bestResult.loc[1]]
// }) - 1
// }
// step 4: find the most possible sentence

@@ -847,5 +806,5 @@ let mostPossibleSentence = null

function createArray(dimension) {
var array = []
const array = []
for (var i = 0; i < dimension; i++) {
for (let i = 0; i < dimension; i++) {
array[i] = []

@@ -857,6 +816,6 @@ }

var firstString = caseSensitive
const firstString = caseSensitive
? firstSequence
: firstSequence.toLowerCase()
var secondString = caseSensitive
const secondString = caseSensitive
? secondSequence

@@ -873,8 +832,8 @@ : secondSequence.toLowerCase()

var firstStringLength = firstString.length
var secondStringLength = secondString.length
var lcsMatrix = createArray(secondStringLength + 1)
const firstStringLength = firstString.length
const secondStringLength = secondString.length
const lcsMatrix = createArray(secondStringLength + 1)
var i
var j
let i
let j
for (i = 0; i <= firstStringLength; i++) {

@@ -898,3 +857,3 @@ lcsMatrix[0][i] = 0

var lcs = ''
let lcs = ''
i = secondStringLength

@@ -901,0 +860,0 @@ j = firstStringLength

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc