update
This commit is contained in:
62
src/util.jl
62
src/util.jl
@@ -770,6 +770,49 @@ function extract_triple_backtick_text(input::String)::Vector{String}
|
||||
end
|
||||
|
||||
|
||||
"""
|
||||
detect_keyword(keywords::AbstractVector{String}, text::String) -> Vector{Union{Nothing, String}}
|
||||
|
||||
Detects if multiple keywords exist in the text in different case variations (lowercase, uppercase first letter, or all uppercase).
|
||||
|
||||
# Arguments:
|
||||
- `keywords::AbstractVector{String}` Vector of keywords to search for
|
||||
- `text::String` The text to search in
|
||||
|
||||
# Returns:
|
||||
- `Vector{Union{Nothing, String}}` Returns a vector containing the matched keyword variations if found, otherwise nothing for each keyword
|
||||
|
||||
# Examples:
|
||||
```jldoctest
|
||||
julia> detect_keyword(["test", "error", "case"], "This is a Test case with ERRORS case")
|
||||
2-element Vector{Union{Nothing, String}}:
|
||||
"Test"
|
||||
"ERRORS"
|
||||
nothing
|
||||
|
||||
julia> detect_keyword(["warning", "missing"], "Warning: data is complete")
|
||||
2-element Vector{Union{Nothing, String}}:
|
||||
"Warning"
|
||||
nothing
|
||||
```
|
||||
|
||||
# Signature
|
||||
"""
|
||||
function detect_keyword(keywords::T, text::String)::Union{Nothing, Dict} where {T<:AbstractVector}
|
||||
kw = Dict{String, Any}()
|
||||
splittext = string.(split(text, " "))
|
||||
# use for loop and detect_keyword function to get the exact variation of each keyword in the text then push to kw list
|
||||
for keyword in keywords
|
||||
ws = detect_keyword.(keyword, splittext)
|
||||
total = sum(issomething.(ws))
|
||||
if total != 0
|
||||
kw[keyword] = total
|
||||
else
|
||||
kw[keyword] = nothing
|
||||
end
|
||||
end
|
||||
return kw
|
||||
end
|
||||
"""
|
||||
detect_keyword(keyword::String, text::String) -> Union{Nothing, String}
|
||||
|
||||
@@ -1075,8 +1118,27 @@ function convertCamelSnakeKebabCase(text::T, tocase::Symbol)::String where {T<:A
|
||||
end
|
||||
|
||||
|
||||
""" Check if a value is not `nothing`.
|
||||
|
||||
# Arguments
|
||||
- `x`: The value to check
|
||||
|
||||
# Returns
|
||||
- `Bool`: `true` if `x` is not `nothing`, `false` otherwise
|
||||
|
||||
# Examples
|
||||
```jldoctest
|
||||
julia> issomething(1)
|
||||
true
|
||||
julia> issomething(nothing)
|
||||
false
|
||||
julia> issomething("test")
|
||||
true
|
||||
````
|
||||
"""
|
||||
function issomething(x)
|
||||
return x === nothing ? false : true
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user