Skip to content

Commit

Permalink
tagging_schemes: excluding 'eval' from the code
Browse files Browse the repository at this point in the history
  • Loading branch information
rssdev10 committed Oct 26, 2023
1 parent e89db72 commit 5778129
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ version = "0.7.5"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Languages = "8ef0a80b-9436-5d2c-a485-80b904378c43"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand Down
16 changes: 8 additions & 8 deletions src/tagging_schemes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
# https://en.wikipedia.org/wiki/Inside%E2%80%93outside%E2%80%93beginning_(tagging)
# https://chameleonmetadata.com/Education/NLP-3/ref_nlp_encoding_schemes_list.php

using InteractiveUtils: subtypes

abstract type tag_scheme end

struct BIO1 <: tag_scheme end # BIO
struct BIO2 <: tag_scheme end
struct BIOES <: tag_scheme end

const available_schemes = ["BIO1", "BIO2", "BIOES"]
const available_schemes = Dict(string(nameof(type)) => type for type in subtypes(tag_scheme))

"""
tag_scheme!(tags, current_scheme::String, new_scheme::String)
Expand Down Expand Up @@ -41,16 +43,14 @@ julia> tags
function tag_scheme!(tags, current_scheme::String, new_scheme::String)
current_scheme = uppercase(current_scheme)
new_scheme = uppercase(new_scheme)
(length(tags) == 0 || current_scheme == new_scheme) && return
(isempty(tags) || isequal(current_scheme, new_scheme)) && return

if new_scheme available_schemes || current_scheme available_schemes
error("Invalid tagging scheme")
end
current_scheme = get(available_schemes, current_scheme, nothing)
new_scheme = get(available_schemes, new_scheme, nothing)

current_scheme = eval(Symbol(current_scheme))()
new_scheme = eval(Symbol(new_scheme))()
(isnothing(current_scheme) || isnothing(new_scheme)) && error("Invalid tagging scheme")

tag_scheme!(tags, current_scheme, new_scheme)
tag_scheme!(tags, current_scheme(), new_scheme())
end

function tag_scheme!(tags, current_scheme::BIO1, new_scheme::BIO2)
Expand Down

0 comments on commit 5778129

Please sign in to comment.