-
Notifications
You must be signed in to change notification settings - Fork 2
/
verifyText() (and requestVerification())
88 lines (72 loc) · 1.77 KB
/
verifyText() (and requestVerification())
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
### verifyText() ###
### The code was developed as part of the project 'Ancient Identities in Modern Britain' (IARH).
### The function shows the use a keyword and fragment of the text in which it features and requests verification of its relevance.
### Returns logical vector.
### Project: Ancient Identities in Modern Britain (IARH); ancientidentities.org
### Author: Marta Krzyzanska
#Requires function requestVerification()
###Part 1. Defining requestVerification()
#Asks the user whether the post is relevant
#Returns user's answer
#When prompted for answer, only 1,2,3 are valid answers
requestVerification <-function(){
cat (noquote("\nIs this post relevant?\nEnter the value from menu:\n\n1.Yes\n2.No\n3.I need more information\n\n"))
x<-scan(file="",nmax=1,quiet=TRUE)
return (x)}
###Part 1. Defining verifyText()
### verifyText() ###
#Variables:
#text - text to be verified
#keyword - keyword searched for in the text
#When prompted for answer, only 1,2,3 are valid answers
verifyText<-function(text, keyword){
e=1
l <- regexpr(keyword, text,ignore.case = TRUE)
b=l[1]-25
c=l[1]+25+nchar(keyword)
if(b<1){
b=1}
if(c>nchar(text)){
c=nchar(text)}
a <- substr(text, b, c)
cat (noquote("\nPost:\n\n"))
cat (" ",a," \n")
d<-requestVerification()
if(d == 1){
f=T
e=3}
else if(d==2){
f=F
e=3}
while (e<3){
if(d==3&&e==1){
e=e+1
b=l[1]-50
c=l[1]+50+nchar(keyword)
if(b<1){
b=1}
if(c>nchar(text)){
c=nchar(text)}
a <- substr(text, b, c)
}
else if(d==3&&e==2){
e=e+1
a<-text
}
cat (noquote("\nPost:\n\n"))
cat (" ",a," \n")
d<-requestVerification()
if(d==1){
f=T
e=3}
else if(d==2){
f=F
e=3}
else if(d==3){e=2}
else{
cat (noquote("\nInvalid input, try again\n"))
e=2
}
}
return (f)
}