Как извлечь предложения между точкой и скобками с помощью R? - PullRequest
0 голосов
/ 01 марта 2019

У меня есть:

Stringa = "Это отличается от первичных данных, созданных специально исследователями для отражения концепций более высокого порядка и более абстрактных (Lee, 1991; Walsham, 1995). ГивенОсновные различия между большими данными и данными, собранными в ходе исследований, вызывают удивление в связи с тем, что мало обсуждается вопрос о том, как использование больших данных должно изменить практику исследований ИБ, основанных на теории. Некоторые ученые отмечают, что сама природа исследования может измениться., учитывая, что большие наборы данных, усовершенствованные алгоритмы и мощные вычислительные возможности могут инициировать и уточнять вопросы без вмешательства человека (Agarwal & Dhar, 2014). Другие комментаторы утверждают, что научный метод, вероятно, устареет, как и в случае «доступности огромныхобъемы данных вместе со статистическими инструментами, позволяющими сократить эти цифры ... наука может развиваться даже без согласованных моделей, единых теорий или вообще никакого механистического объяснения »(Anderson, 2008).Ученые больше не должны сделать обоснованные предположения, строить гипотезы и модели, проверить их в экспериментах andexamples данных на основе.Вместо этого они могут собрать полный набор данных для образцов, которые раскрывают эффекты, производя научные выводы без дальнейших экспериментов »(Prensky, 2009)."

Требуемый вывод:

[1]This is different from primary data created specifically by researchers to reflect concepts that are higher-order and more abstract(Lee,1991;Walsham,1995).
[2]Some scholars have noted that the very nature of inquiry is likely to change, given that large data sets, advanced algorithms, and powerful computing capabilities can initiate and refine questions without human intervention (Agarwal & Dhar, 2014)
[3] Other commentators argue that the scientific method is likely to become obsolete, as with the “availability of huge amounts of data, along with the statistical tools to crunch these numbers … science can advance even without coherent models, unified theories, or really any mechanistic explanation at all” (Anderson, 2008)
[4]Instead, they canmine thecomplete setof data forpatterns that reveal effects, producing scientific conclusions without further experimentation” (Prensky, 2009)

Я использую: unlist(str_extract_all(string =Stringa, pattern = "\\. [A-Za-z][^()]+ \\(")) Но это не работает

Я не хочу извлекать 'Учитывая основныеРазличия между большими данными и данными, собранными в исследованиях, удивительно, как мало дискуссий о том, как использование больших данных должно изменить практику основанных на теории исследований в области ИБ. »и« Возможно », ученым больше не нужно делать обоснованные предположения, строить гипотезыи модели, проверить их в экспериментах на основе данных и на примерах. '

Ответы [ 2 ]

0 голосов
/ 01 марта 2019

Если в тексте нет сокращений, вы можете использовать

regmatches(Stringa, gregexpr("[^.?!\\s][^.!?]*?\\([^()]*\\)", Stringa, perl=TRUE))
[[1]]
[1] "This is different from primary data created specifically by researchers to reflect concepts that are higher-order and more abstract(Lee,1991;Walsham,1995)"                                                                                                                                                                         
[2] "Some scholars have noted that the very nature of inquiry is likely to change, given that large data sets, advanced algorithms, and powerful computing capabilities can initiate and refine questions without human intervention (Agarwal & Dhar, 2014)"                                                                           
[3] "Other commentators argue that the scientific method is likely to become obsolete, as with the “availability of huge amounts of data, along with the statistical tools to crunch these numbers … science can advance even without coherent models, unified theories, or really any mechanistic explanation at all” (Anderson, 2008)"
[4] "Instead, they canmine thecomplete setof data forpatterns that reveal effects, producing scientificconclusions without further experimentation” (Prensky, 2009)"                                                                                                                                                                    

См. Демонстрацию regex и демонстрацию R .

Подробности

  • [^.?!\\s] - любой символ, кроме ., ?, ! и пробел
  • [^.!?]*? - любой 0+символы, отличные от ., ?, !, как можно меньше
  • \([^()]*\) - (, 0+ символов, отличных от ( и ), а затем ).
0 голосов
/ 01 марта 2019

Мы можем справиться с этим, используя grepexpr и regmatches, используя следующий шаблон регулярных выражений:

.*?\([^)]+\).*?(?=\w|$)

Это будет захватывать любой контент вплоть до первой круглой скобки, за которым следует термин (...).Сценарий ниже будет захватывать все такие совпадения в исходном тексте.

m <- gregexpr(".*?\\([^)]+\\).*?(?=\\w|$)", x, perl=TRUE)
regmatches(x, m)

[[1]]
[1] "This is different from primary data created specifically by researchers to reflect concepts that are higher-order and more abstract(Lee,1991;Walsham,1995)."                                                                                                                                                                                                                                                                                                              
[2] "Given the major differences between big data and research-collected data, it is surprising how little discussion has arisen about how using big data should change the practice of theory-informed IS research. Some scholars have noted that the very nature of inquiry is likely to change, given that large data sets, advanced algorithms, and powerful computing capabilities can initiate and refine questions without human intervention (Agarwal & Dhar, 2014). "
[3] "Other commentators argue that the scientific method is likely to become obsolete, as with the “availability of huge amounts of data, along with the statistical tools to crunch these numbers … science can advance even without coherent models, unified theories, or really any mechanistic explanation at all” (Anderson, 2008). "
[4] "Perhaps “scientists no longer have to make educated guesses, construct hypotheses and models, test them in data-based experiments andexamples. Instead, they canmine thecomplete setof data forpatterns that reveal effects, producing scientificconclusions without further experimentation”(Prensky, 2009). "
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...