Skip to content

Instantly share code, notes, and snippets.

@asderix
Created April 23, 2019 08:41
Show Gist options
  • Save asderix/f7d0351c5df1d55166db3c5412d9c11b to your computer and use it in GitHub Desktop.
Save asderix/f7d0351c5df1d55166db3c5412d9c11b to your computer and use it in GitHub Desktop.
ESC example for Scala
/**
* author: Ronny Fuchs, info@asderix.com
* license: Apache license 2.0 - https://www.apache.org/licenses/
*/
package esc.scala.example
import esc.similarity._
import esc.commons._
import esc.index._
object Main extends App {
// --- Similarity ---:
val sim = new NameSimilarity
// Calculate the similarity of two persons:
println("Pers.-Name sim: " + sim.getPersonNameSimilarity("Bill Gates", "William Henry Gates").similarity)
// Calculate the similarity of two organisations:
println("Org.-Name sim: " + sim.getOrganisationNameSimilarity("Microsoft (Schweiz) AG", "Microspot (Switerland) Ltd.").similarity)
// --- Indexer ---:
// Create an indexer:
val indexer = IndexFactory.openOrCreateIndex("C:\\Tmp\\", "JavaExampleIndex1")
// A person to index.
val person = new IndexPerson("id1234",
"exid1234",
"Hanspeter Müller",
List("31.12.1980"),
List("Switzerland", "DE"))
// Index the person.
indexer.addPerson(person)
// Commit and close the indexer.
indexer.commit()
indexer.close()
// Create a Finder:
val finder = IndexFactory.openIndexForSearch("C:\\Tmp\\", "JavaExampleIndex1")
// Find a person.
val matches = finder.findPerson("Hans-Peter Müller-Meyer", List("1981"), List())
println("Matches:")
println(matches.toString())
println("Access matchPairs:")
println(matches(0).matchResult.matchPairs.toString())
scala.io.StdIn.readLine("") // press any key to exit the application.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment