STAY WITH US

[Hindi]NLP 25# Sentence Segmentation P.1 |NLP|Python 3|Natural Language Processing|2019

[Hindi]NLP 25# Sentence Segmentation P.1  |NLP|Python 3|Natural Language Processing|2019


Code:

# -*- coding: utf-8 -*-
"""NLP_Ex17.ipynb

Automatically generated by Colaboratory.


"""

import spacy

nlp = spacy.load('en_core_web_sm')

doc = nlp(u"This is the first sentence. This is the another sentence. This is the last sentence.")

for sent in doc.sents:
  print(sent)

doc[0]

type(list(doc.sents)[0])

doc = nlp(u'"Management is doing things right; leadership is doing the right things." -Peter Drucker')

doc.text

for sent in doc.sents:
  print(sent)
  print('\n')

def set_custom_boundraies1(doc):
  for token in doc:
    print(token.i)
    print(token)

set_custom_boundraies1(doc)

def set_custom_boundaries(doc):
    for token in doc[:-1]:
        if token.text == ';':
            doc[token.i+1].is_sent_start = True
    return doc

nlp.add_pipe(set_custom_boundaries,before='parser')

nlp.pipe_names

doc = nlp(u'"Management is doing things right; leadership is doing the right things." -Peter Drucker')

for sent in doc.sents:
  print(sent)

YouTube:



Recommended Book:

Post a Comment

0 Comments