update
This commit is contained in:
20
src/util.jl
20
src/util.jl
@@ -3,7 +3,7 @@ module util
|
||||
export timedifference, showstracktrace, findHighestIndexKey, uuid4snakecase, replaceDictKeys,
|
||||
findMatchingDictKey, textToDict, randstring, randstrings, timeout,
|
||||
dataframeToCSV, dfToVectorDict, disintegrate_vectorDict, getDataFrameValue, dfRowtoString,
|
||||
dfToString, dataframe_to_json_list, dict_to_string, extract_triple_backtick_text
|
||||
dfToString, dataframe_to_json_list, dict_to_string, extract_triple_backtick_text, countGivenWords
|
||||
|
||||
using JSON3, DataStructures, Distributions, Random, Dates, UUIDs, MQTTClient, DataFrames
|
||||
|
||||
@@ -733,13 +733,13 @@ Extracts text enclosed within triple backticks (```) from the given string.
|
||||
"""
|
||||
function extract_triple_backtick_text(input::String)::Vector{String}
|
||||
# Regular expression to match text wrapped by triple backticks
|
||||
regex = r"(```)(.*?)(```)"
|
||||
regex = r"```([\s\S]*?)```"
|
||||
|
||||
# Find all matches in the input string
|
||||
matches = collect(eachmatch(regex, input))
|
||||
|
||||
# Extract the matched text (excluding the backticks)
|
||||
extracted_text = [m.captures[2] for m in matches]
|
||||
extracted_text = [m.captures[1] for m in matches]
|
||||
|
||||
return extracted_text
|
||||
end
|
||||
@@ -787,6 +787,20 @@ function detect_keyword(keyword::String, text::String)::Union{Nothing, String}
|
||||
end
|
||||
|
||||
|
||||
""" count a given word in a text """
|
||||
function countGivenWords(text::String, words::Vector{String})::Vector{Int}
|
||||
count = []
|
||||
|
||||
# loop through each word in words
|
||||
for word in words
|
||||
# initialize a counter for the current word
|
||||
splittext = split(text, word)
|
||||
splittext_length = length(splittext)
|
||||
thisWordCount = splittext_length - 1
|
||||
push!(count, thisWordCount)
|
||||
end
|
||||
return count
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user