Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow DocumentMetadata to hold arbirtary data #158

Merged
merged 5 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 33 additions & 24 deletions src/document.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,41 @@
##############################################################################

mutable struct DocumentMetadata
language
title::String
author::String
timestamp::String
language::Language
title::AbstractString
author::AbstractString
timestamp::AbstractString
custom::Any

@doc """
DocumentMetadata(
language::Language,
title::String,
author::String,
timestamp::String,
custom::Any
)

Stores basic metadata about Document.

...
# Arguments
- `language`: What language is the document in? Defaults to Languages.English(), a Language instance defined by the Languages package.
- `title::String` : What is the title of the document? Defaults to "Untitled Document".
- `author::String` : Who wrote the document? Defaults to "Unknown Author".
- `timestamp::String` : When was the document written? Defaults to "Unknown Time".
- `custom` : user specific data field. Defaults to nothing.
...
"""
DocumentMetadata(
language::Language=Languages.English(),
title::AbstractString="Untitled Document",
author::AbstractString="Unknown Author",
timestamp::AbstractString="Unknown Time",
custom::Any=nothing
) = new(language, title, author, timestamp, custom)
end

"""
DocumentMetadata(language, title::String, author::String, timestamp::String)

Stores basic metadata about Document.

...
# Arguments
- `language`: What language is the document in? Defaults to Languages.English(), a Language instance defined by the Languages package.
- `title::String` : What is the title of the document? Defaults to "Untitled Document".
- `author::String` : Who wrote the document? Defaults to "Unknown Author".
- `timestamp::String` : When was the document written? Defaults to "Unknown Time".
...
"""
DocumentMetadata() = DocumentMetadata(
Languages.English(),
"Untitled Document",
"Unknown Author",
"Unknown Time"
)

##############################################################################
#
# The abstract Document type
Expand Down
12 changes: 12 additions & 0 deletions test/document.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@

@testset "Document" begin

dmeta = TextAnalysis.DocumentMetadata(Languages.English(), "test title", "test author", "test time", Dict(:k1=>"v1", :k2=>"v2"))
@test (dmeta.language == Languages.English()) &&
(dmeta.title == "test title") &&
(dmeta.author == "test author") &&
(dmeta.timestamp == "test time") &&
(get(dmeta.custom, :k1, "") == "v1") &&
(get(dmeta.custom, :k2, "") == "v2")

# mutability
dmeta.custom = nothing
@test isnothing(dmeta.custom)

sample_text1 = "This is a string"
sample_text2 = "This is also a string"
sample_file = joinpath(dirname(@__FILE__), "data", "poem.txt")
Expand Down
Loading