Skip to content

Commit

Permalink
fixed a whitespace bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nix2intel committed Aug 12, 2024
1 parent a923406 commit daacb6a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
22 changes: 15 additions & 7 deletions lib/entityfingerprint/fingerprint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,22 @@ defmodule EntityFingerprint.Fingerprint do
- \[Clustering in Depth\](https://github.com/OpenRefine/OpenRefine/wiki/Clustering-In-Depth), part of the OpenRefine documentation discussing how to create collisions in data clustering.
"""
def create(entity) do
abbreviated_entity = abbreviate_entity(entity)
fingerprint = create_fingerprint(abbreviated_entity)
#We use the abbreviated entity to gat the script, because of potential whitespace at beginning of word
[script_atom | _] = Unicode.script(abbreviated_entity)
script = Atom.to_string(script_atom)
{:ok, fingerprint: fingerprint, original: entity, script: script}
def create(entity) do
abbreviated_entity = abbreviate_entity(entity)
fingerprint = create_fingerprint(abbreviated_entity)

if String.trim(abbreviated_entity) == "" do
{:error, "Entity perfectly matches abbreviation: " <> entity}
else
case Unicode.script(abbreviated_entity) do
[script_atom | _] ->
script = Atom.to_string(script_atom)
{:ok, fingerprint: fingerprint, original: entity, script: script}
_ ->
{:error, "Failed to get script for entity: " <> entity}
end
end
end

defp abbreviate_entity(entity) do
entity
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule EntityFingerprint.MixProject do
def project do
[
app: :entityfingerprint,
version: "0.1.1",
version: "0.1.2",
elixir: "~> 1.16",
start_permanent: Mix.env() == :prod,
deps: deps(),
Expand Down
9 changes: 9 additions & 0 deletions test/entityfingerprint_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ defmodule EntityFingerprint.FingerprintTest do
assert Fingerprint.create(entity) ==
{:ok, [fingerprint: "new york", original: "New York, New York", script: "latin"]}
end

test "create fingerprint for empty abbreviation" do
entity = "CHAMBRE DE COMMERCE"

assert Fingerprint.create(entity) ==
{:error, "Entity perfectly matches abbreviation: CHAMBRE DE COMMERCE" }
end



test "create fingerprint for Google" do
entity = "Google Limited Liability Company !!!"
Expand Down

0 comments on commit daacb6a

Please sign in to comment.