단락 시작 부분에서 단일 공백을 제거하고 파이썬을 사용하여 단락 첫 글자를 대문자로 만드는 방법은 무엇입니까?선행 공백 및 대문자
입력 :
this is a sample sentence. This is a sample second sentence.
출력 : 지금까지
This is a sample sentence. This is a sample second sentence.
내 노력 :
import spacy, re
nlp = spacy.load('en_core_web_sm')
doc = nlp(unicode(open('2.txt').read().decode('utf8')))
tagged_sent = [(w.text, w.tag_) for w in doc]
normalized_sent = [w.capitalize() if t in ["NN","NNS"] else w for (w,t) in tagged_sent]
normalized_sent1 = normalized_sent[0].capitalize()
string = re.sub(" (?=[\.,'!?:;])", "", ' '.join(normalized_sent1))
rtn = re.split('([.!?] *)', string)
final = ''.join([i.capitalize() for i in rtn])
print final
이 단락의 시작을 제외한 모든 단락의 문장의 첫 단어를 대문자로?
Output:
on the insert tab, the galleries include items that are designed to coordinate with the overall look of your document. You can use these galleries to insert tables, headers, footers, lists, cover pages, and other document building blocks. When you create pictures, charts, or diagrams, they also coordinate with your current document look.
Expected output:
On the insert tab, the galleries include items that are designed to coordinate with the overall look of your document. You can use these galleries to insert tables, headers, footers, lists, cover pages, and other document building blocks. When you create pictures, charts, or diagrams, they also coordinate with your current document look.
지금까지 시도 무엇 ? 코드를 게시하십시오. – James
"단락"을 정의하십시오. – Sweeper
'nltk' 라이브러리를 사용해도 될까요? –