main content

erase punctuation from text and documents -凯发k8网页登录

erase punctuation from text and documents

description

example

newstr = erasepunctuation(str) erases punctuation and symbols from the elements of str. the function removes characters that belong to the unicode punctuation or symbol classes.

example

newdocuments = erasepunctuation(documents) erases punctuation and symbols from documents. if a word is empty after removing punctuation and symbol characters, then the function removes it. for tokenized document input, the function erases punctuation from tokens with type 'punctuation' and 'other'. for example, the function does not erase punctuation and symbol characters from urls and email addresses.

example

newdocuments = erasepunctuation(documents,'tokentypes',types) erases punctuation and symbols from only the specified token types.

examples

erase the punctuation from the text in str.

str = "it's one and/or two.";
newstr = erasepunctuation(str)
newstr = 
"its one andor two"

to insert a space where the "/" symbol is, first use the replace function.

newstr = replace(str,"/"," ")
newstr = 
"it's one and or two."
newstr = erasepunctuation(newstr)
newstr = 
"its one and or two"

erase the punctuation from an array of documents.

documents = tokenizeddocument([ ...
    "an example of a short sentence." 
    "another example... with a url: https://www.mathworks.com"])
documents = 
  2x1 tokenizeddocument:
     7 tokens: an example of a short sentence .
    10 tokens: another example . . . with a url : https://www.mathworks.com
newdocuments = erasepunctuation(documents)
newdocuments = 
  2x1 tokenizeddocument:
    6 tokens: an example of a short sentence
    6 tokens: another example with a url https://www.mathworks.com

here, the function does not erase the punctuation symbols from the url.

input arguments

input text, specified as a string array, character vector, or cell array of character vectors.

example: ["an example of a short sentence."; "a second short sentence."]

data types: string | char | cell

input documents, specified as a tokenizeddocument array.

token types to erase punctuation from, specified as a character vector, string array, or a cell array of character vectors containing one or more token types (including custom token types).

the tokenizeddocument and functions automatically detect the following token types:

  • letters — string of letter characters only

  • digits — string of digits only

  • punctuation — string of punctuation and symbol characters only

  • email-address — detected email address

  • web-address — detected web address

  • hashtag — detected hashtag (starts with "#" character followed by a letter)

  • at-mention — detected at-mention (starts with "@" character)

  • emoticon — detected emoticon

  • emoji — detected emoji

  • other — does not belong to the previous types and is not a custom type

to specify your own custom token types when tokenizing, use the 'customtokens' or 'regularexpressions' options in tokenizeddocument. if you do not specify a type for a custom token, then the software sets the corresponding token type to 'custom'.

data types: string | char | cell

output arguments

output text, returned as a string array, character vector, or cell array of character vectors. str and newstr have the same data type.

output documents, returned as a tokenizeddocument array.

more about

unicode character categories

each unicode character is assigned a category. the following table summarizes the unicode punctuation and symbol categories and provides an example character from each category:

categorycategory codenumber of charactersexample character
punctuation, connector[pc]10_
punctuation, dash[pd]24-
punctuation, close[pe]73)
punctuation, final quote[pf]10
punctuation, initial quote[pi]12
punctuation, other[po]566!
punctuation, open[ps]75(
symbol, currency[sc]54$
symbol, modifier[sk]121^
symbol, math[sm]948
symbol, other[so]5855¦

for more information, see [1].

tips

  • for string input, erasepunctuation removes punctuation characters from urls and html tags. this behavior can prevent the functions , eraseurls, and from working as expected. if you want to use these functions to preprocess your text, then use these functions before using erasepunctuation.

references

[1] unicode character categories.

version history

introduced in r2017b
网站地图