📄 extractsentencedoc.cpp
字号:
// ExtractSentenceDoc.cpp : implementation of the CExtractSentenceDoc class
//
#include "stdafx.h"
#include "ExtractSentence.h"
#include "LWORDSet.h"
#include "ExtractSentenceDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define MAXLENGTH 10000
/////////////////////////////////////////////////////////////////////////////
// CExtractSentenceDoc
IMPLEMENT_DYNCREATE(CExtractSentenceDoc, CDocument)
BEGIN_MESSAGE_MAP(CExtractSentenceDoc, CDocument)
//{{AFX_MSG_MAP(CExtractSentenceDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CExtractSentenceDoc construction/destruction
CExtractSentenceDoc::CExtractSentenceDoc()
{
// TODO: add one-time construction code here
}
CExtractSentenceDoc::~CExtractSentenceDoc()
{
}
BOOL CExtractSentenceDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CExtractSentenceDoc serialization
void CExtractSentenceDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CExtractSentenceDoc diagnostics
#ifdef _DEBUG
void CExtractSentenceDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CExtractSentenceDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CExtractSentenceDoc commands
void CExtractSentenceDoc::splitParagraph(char *paragraph, char *sentence[MAXSENTENCE])
{
int locateFullStop = 10000, locateQuestionMark = 10000, locateExclamationMark = 10000;
int locate = 0;
char *pLocate;
int i, index = 0;
int nLen = lstrlen(paragraph);
char remainSentences[10000];
//get the remain sentences from paragraph, all of the operations base on the remainSentences[]
for (i = 0; i < lstrlen(paragraph); i++)
{
*(remainSentences + i) = *(paragraph + i);
}
remainSentences[lstrlen(paragraph)] = '\0';
//if there are no 。?!
if (!strstr(paragraph, "。") && !strstr(paragraph, "?") && !strstr(paragraph, "!"))
{
//put the paragraph into sentence[0] as a single sentence
sentence[0] = new char[lstrlen(paragraph) + 1];
strncpy(sentence[0], paragraph, lstrlen(paragraph) + 1);
}
else
{
index = 0;
while (*(remainSentences) != '\0')
{
//init
locateFullStop = 10000;
locateQuestionMark = 10000;
locateExclamationMark = 10000;
//get the position of 。?!
if ((pLocate = strstr(remainSentences, "。")) != NULL)
{
locateFullStop = (int)(pLocate - remainSentences + 1);
}
if ((pLocate = strstr(remainSentences, "?")) != NULL)
{
locateQuestionMark = (int)(pLocate - remainSentences + 1);
}
if ((pLocate = strstr(remainSentences, "!")) != NULL)
{
locateExclamationMark = (int)(pLocate - remainSentences + 1);
}
//if there is no 。?!in the current sentences
if (locateFullStop == 10000 && locateQuestionMark == 10000 && locateExclamationMark == 10000)
{
sentence[index] = new char[lstrlen(remainSentences) + 1];
strncpy(sentence[index], remainSentences, lstrlen(remainSentences));
sentence[index][lstrlen(remainSentences)] = '\0';
*(remainSentences) = '\0';
}
else
{
//find the position of the first sentence in the paragraph
if (locateFullStop < locateQuestionMark)
locate = locateFullStop;
else
locate = locateQuestionMark;
if (locateExclamationMark < locate)
locate = locateExclamationMark;
//get s sentence in the paragraph
sentence[index] = new char[locate + 2];
strncpy(sentence[index], remainSentences, locate + 1);
sentence[index][locate + 1] = '\0';
//get the remain sentences
int j = 0;
while (remainSentences[j + locate + 1] != '\0')
{
remainSentences[j] = remainSentences[j + locate + 1];
j++;
}
remainSentences[j] = '\0';
index++;
}
}
}
}
bool CExtractSentenceDoc::searchTermsInSentence(char *sen, CString term)
{
char word[50];
for (int i = 0; i < term.GetLength(); i++)
{
word[i] = term[i];
}
word[i] = '\0';
if (strstr(sen, word) == NULL)
return false;
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -