-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
AnnotatedString has no public way to extract the underlying string without annotations #55247
Comments
Isn't |
Not really, it always converts to julia> ans = Base.AnnotatedString(InlineString("abc"))
julia> ans.string |> typeof
String3
julia> String(ans) |> typeof
String I guess |
an why not a simple accessor |
Any public function would work, Although, |
Why are you putting exotic strings in and out of AnnotatedString? What's the use case? |
AnnotatedStrings appear to be a nice fit for all kinds of natural language processing applications. The task of annotating certain sections of a string is very common there, and it would be convenient to rely on the common implementation in Base! When strings are large, or there are many of them, the builtin |
How about this? (T)(s::Base.AnnotatedString{T}) where {T <: AbstractString} = s.string |
Any public "get me the underlying string without annotations" function would be fine! It should also support this case where julia> s1 = Base.AnnotatedString(InlineString("abc"), [(2:3, :x => 123)])
"abc"
julia> s2 = view(s1, 1:2)
"ab"
# s2 is a string with anotations – here are annotations:
julia> Base.annotations(s2)
1-element Vector{Tuple{UnitRange{Int64}, Pair{Symbol, Any}}}:
(2:2, :x => 123)
# but how to get the underlying string?..
# this is clearly wrong:
julia> s2.string
"abc" |
You're calling |
That's one of the reasons a function to "strip annotations" would be useful. It should be applicable whenever |
I don't think that could work with arbitrary wrapper types. The That said, we can add the same level of support via a |
Surely a function
|
Basically, there are some string types that are considered "annotated" – support |
I think my previous comment should mostly answer these questions. To clarify though:
|
I think such an operation would be spelled |
This generalization of the (::Type{T})(s::Base.AnnotatedString) where {T <: AbstractString} = T(s.string) |
The AnnotatedString docstring explicitly states
As far as I see, the only way to get the underlying (abstract)string is by accessing the
string
field which is not public. I guess this is an undesirable situation?..The text was updated successfully, but these errors were encountered: