npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

string-similarity-arraylist

v1.0.3

Published

Finds degree of similarity in list of array of objects , based on Dice's Coefficient, which is mostly better than Levenshtein distance.

Downloads

9

Readme

string-similarity-arraylist

Finds degree of similarity in list of array of objects , array of strings and two stings based on Dice's Coefficient which is way better than Levenshtein distance.

Installation

For Node Js

npm install string-similarity-arraylist --save

Once the package is installed, you can import the library using import or require approach:

Usage


const {

    getSimilarityofArrayOfObjects,
    getSimilarityScaleofArrayOfObjects
    getSimilarityOfArrayOfStrings,
    getSimilarityOfTwoString,
    
    } = require('string-similarity-arraylist')

or


import { 
    
    getSimilarityofArrayOfObjects ,
    getSimilarityScaleofArrayOfObjects ,
    getSimilarityOfArrayOfStrings,
    getSimilarityOfTwoString 
    
    } from 'string-similarity-arraylist'

For browser apps

Include <script src="//cdn.jsdelivr.net/npm/string-similarity-arraylist/index.min.js"></script> to get the latest version.

Or <script src="//cdn.jsdelivr.net/npm/[email protected]/index.min.js"></script> to get a specific version (1.0.1) in this case.

This exposes a global variable called getSimilarityofArrayOfObjects , getSimilarityScaleofArrayOfObjects , getSimilarityOfArrayOfStrings , getSimilarityOfTwoString which you can start using.

    <script>

     const data = getSimilarityofArrayOfObjects({

                             data: Array Of Objects,
                             rawText: String,
                             objectMatchingKeys: Array of Object key,
                             similarityScale: Scale of Similarity (0 - 1)
                             sortingOrder: default None ,
                             itemsToBeRendered: Number of Items Return,
                             callback: Return Best Match
            
                         });

      console.log(data)    // All Filtered Lists             

    </script>

API

The package contains Four methods:

getSimilarityofArrayOfObjects({ data:Array , rawText:String , objectMatchingKeys:Array , similarityScale:Number , sortingOrder:Number , itemsToBeRendered:Number , callback:Function })

Returns All Items whose fraction between 0 and 1, which indicates the degree of similarity of your word with mentioned objects keys of array items as per similarityScale value . 0 indicates completely different object item , 1 indicates identical object item . The comparison is case-sensitive.

Arguments
  1. data : Array Of object
  2. rawText : The string that you waana match
  3. objectMatchingKeys : Array of keys of an object
  4. similarityScale : Number or fraction value from finding start -> Default 0
  5. sortingOrder : Number -> 1 for DESC and 0 for ASC , Default None
  6. itemsToBeRendered : Number Of Items Return -> Default all items
  7. callback: Function -> Return Best Matched Item and Index of that matched item from Given List

Examples


const array1 = [
    { name: "John", age: 25, city: "New York" },
    { name: "Alice", age: 30, city: "Los Angeles" },
    { name: "Bob", age: 28, city: "Chicago" }
];

 const datavalue =   getSimilarityofArrayOfObjects({
    data:array1,
    similarityScale:0,
    rawText:'find john in the list',
    objectMatchingKeys:['name'],
    sortingOrder:1,
    itemsToBeRendered:2
})


console.log(datavalue)  

// Return Item

[
  {
    item: { name: 'John', age: 25, city: 'New York' },
    similarityScale: { name: 0.3157894736842105 },        // describe each key similarityScale
    averageSimilarityScale: 0.3157894736842105            // describe average similarityScale of all mentioned key of an object
  },
  {
    item: { name: 'Alice', age: 30, city: 'Los Angeles' },
    similarityScale: { name: 0.1 },
    averageSimilarityScale: 0.1
  }
]


// callback Item

{
  bestMatch: {
    item: { name: 'John', age: 25, city: 'New York' },
    similarityScale: { name: 0.3157894736842105 },
    averageSimilarityScale: 0.3157894736842105
  },
  bestMatchIndex: 0
}

getSimilarityScaleofArrayOfObjects({ data:Array , rawText:String , objectMatchingKeys:Array , sortingOrder:Number , itemsToBeRendered:Number })

Returns all Items whose fraction between 0 and 1, which indicates the degree of similarity of your word with mentioned objects keys of array items. 0 indicates completely different object item , 1 indicates identical object item . The comparison is case-sensitive.

Arguments
  1. data : Array Of object
  2. rawText : The string that you waana match
  3. objectMatchingKeys : Array of keys of an object
  4. sortingOrder : Number -> 1 for DESC and 0 for ASC , Default None
  5. itemsToBeRendered : Number Of Items Return -> Default All Item

Examples


const array1 = [
    { name: "John", age: 25, city: "New York" },
    { name: "Alice", age: 30, city: "Los Angeles" },
    { name: "Bob", age: 28, city: "Chicago" }
];

 const datavalue =   getSimilarityScaleofArrayOfObjects({
    data:array1,
    rawText:'find john in the list',
    objectMatchingKeys:['name'],
})


console.log(datavalue)  

// Return All Items

[
 {
    item: { name: 'John', age: 25, city: 'New York' },
    similarityScale: { name: 0.3157894736842105 },        // describe each key similarityScale
    averageSimilarityScale: 0.3157894736842105            // describe average similarityScale of all mentioned key of an object
  },
  {
    item: { name: 'Alice', age: 30, city: 'Los Angeles' },
    similarityScale: { name: 0.1 },
    averageSimilarityScale: 0.1
  },
  {
    item: { name: 'Bob', age: 28, city: 'Chicago' },
    similarityScale: { name: 0 },
    averageSimilarityScale: 0
  }
]

getSimilarityOfArrayOfStrings({ data:Array of String , rawText:String , sortingOrder:Number , itemsToBeRendered:Number , callback:Function})

Returns all Items whose fraction between 0 and 1, which indicates the degree of similarity of your word with mentioned Array of strings. 0 indicates completely different strings , 1 indicates identical string. The comparison is case-sensitive.

Arguments
  1. data : Array Of Strings
  2. rawText : The string that you waana match
  3. sortingOrder : Number -> 1 for DESC and 0 for ASC , Default None
  4. itemsToBeRendered : Number Of Items Return -> Default all items
  5. callback: Function -> Return Best Matched Item and Index of that matched item from Given List

Examples


const array1 = [
  "The quick brown fox jumps over the lazy dog.",
  "She sells seashells by the seashore.",
  "The sun rises in the east and sets in the west.",
  "Coding is a valuable skill in the modern world.",
  "Learning new things is a lifelong journey."
]

 const datavalue =   getSimilarityOfArrayOfStrings({
    arrayOfStrings:array1,
    rawText:'sun is getting rises in east'
})


console.log(datavalue)  

// Return All Items

[
  {
    targetString: 'The quick brown fox jumps over the lazy dog.',
    similarityScale: 0
  },
  {
    targetString: 'She sells seashells by the seashore.',
    similarityScale: 0.15384615384615385
  },
  {
    targetString: 'The sun rises in the east and sets in the west.',
    similarityScale: 0.4482758620689655                                               // describe similarityScale of string
  },
  {
    targetString: 'Coding is a valuable skill in the modern world.',
    similarityScale: 0.16666666666666666
  },
  {
    targetString: 'Learning new things is a lifelong journey.',
    similarityScale: 0.2807017543859649
  }
]


// callback Item

{
  bestMatch: {
    targetString: 'The sun rises in the east and sets in the west.',
    similarityScale: 0.4482758620689655
  },
  bestMatchIndex: 2
}

getSimilarityOfTwoString(string1,string2)

Returns fraction between 0 and 1, which indicates the degree of similarity of your two strings. 0 indicates completely different strings , 1 indicates identical string. The comparison is case-sensitive.

Arguments
  1. string1 : First String
  2. string2 : Second String

Examples



var datavalue = getSimilarityOfTwoString('She enjoys reading books in her free time.','She loves reading books during her leisure hours.');

console.log(datavalue)


// Return similarityScale of your both strings

{ similarityScale: 0.48 }

Documentation of Api Content

Here we mentioned our default value of Parameter of an Api's .

The general structure of api's as follows:

| Property | Value | Default Value | | :------------ |:---------------:| -----:| | data | Array Of Object | Blank Array | | rawText | String | Blank String | | similarityScale | Number or Fractional Value | Zero | | objectMatchingKeys | Array of Object Keys | Blank Array | | sortingOrder | Number ( 0 - 1 ) | null | | itemsToBeRendered | Number ( 0 - Array Length ) | Array Length | | callback | Function | Function | | string1 | string | null | | string2 | string | null |

Release Notes

Version 1.0.2 : Released getSimilarityOfArrayOfStrings and getSimilarityOfTwoString .

Version 1.0.1 : Released getSimilarityofArrayOfObjects and getSimilarityScaleofArrayOfObjects .

Resourses

Spacy.js

TensorFlow.js

NLU