Repository navigation
Expand file tree
/
Copy pathFunctionCuration.R
More file actions
642 lines (494 loc) · 43.4 KB
/
Copy pathFunctionCuration.R
File metadata and controls
642 lines (494 loc) · 43.4 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
# Script to curate FracFocus purpose data
#Kristin Isaacs, EPA/ORD/CCTE 2025
library("tidyr")
library("dplyr")
#If doing this for the first time, load in FracFocus CSV data and store key data as RDS files for ease of access
#load<-1 #flag for loading
load<-0
if (load==1) {
#this is not code-efficient, but easy
file1<-read.csv("FracFocusCSV/FracFocusRegistry_1.csv")
file2<-read.csv("FracFocusCSV/FracFocusRegistry_2.csv")
file3<-read.csv("FracFocusCSV/FracFocusRegistry_3.csv")
file4<-read.csv("FracFocusCSV/FracFocusRegistry_4.csv")
file5<-read.csv("FracFocusCSV/FracFocusRegistry_5.csv")
file6<-read.csv("FracFocusCSV/FracFocusRegistry_6.csv")
file7<-read.csv("FracFocusCSV/FracFocusRegistry_7.csv")
file8<-read.csv("FracFocusCSV/FracFocusRegistry_8.csv")
file9<-read.csv("FracFocusCSV/FracFocusRegistry_9.csv")
file10<-read.csv("FracFocusCSV/FracFocusRegistry_10.csv")
file11<-read.csv("FracFocusCSV/FracFocusRegistry_11.csv")
file12<-read.csv("FracFocusCSV/FracFocusRegistry_12.csv")
file13<-read.csv("FracFocusCSV/FracFocusRegistry_13.csv")
ingredients1<-file1[which(file1$IngredientsId!=""),c("DisclosureId","WellName","Latitude","Longitude","IngredientsId","IngredientCommonName","CASNumber","IngredientName","Purpose","PurposeId","Supplier","TradeName")]
ingredients2<-file2[which(file2$IngredientsId!=""),c("DisclosureId","WellName","Latitude","Longitude","IngredientsId","IngredientCommonName","CASNumber","IngredientName","Purpose","PurposeId","Supplier","TradeName")]
ingredients3<-file3[which(file3$IngredientsId!=""),c("DisclosureId","WellName","Latitude","Longitude","IngredientsId","IngredientCommonName","CASNumber","IngredientName","Purpose","PurposeId","Supplier","TradeName")]
ingredients4<-file4[which(file4$IngredientsId!=""),c("DisclosureId","WellName","Latitude","Longitude","IngredientsId","IngredientCommonName","CASNumber","IngredientName","Purpose","PurposeId","Supplier","TradeName")]
ingredients5<-file5[which(file5$IngredientsId!=""),c("DisclosureId","WellName","Latitude","Longitude","IngredientsId","IngredientCommonName","CASNumber","IngredientName","Purpose","PurposeId","Supplier","TradeName")]
ingredients6<-file6[which(file6$IngredientsId!=""),c("DisclosureId","WellName","Latitude","Longitude","IngredientsId","IngredientCommonName","CASNumber","IngredientName","Purpose","PurposeId","Supplier","TradeName")]
ingredients7<-file7[which(file7$IngredientsId!=""),c("DisclosureId","WellName","Latitude","Longitude","IngredientsId","IngredientCommonName","CASNumber","IngredientName","Purpose","PurposeId","Supplier","TradeName")]
ingredients8<-file8[which(file8$IngredientsId!=""),c("DisclosureId","WellName","Latitude","Longitude","IngredientsId","IngredientCommonName","CASNumber","IngredientName","Purpose","PurposeId","Supplier","TradeName")]
ingredients9<-file9[which(file9$IngredientsId!=""),c("DisclosureId","WellName","Latitude","Longitude","IngredientsId","IngredientCommonName","CASNumber","IngredientName","Purpose","PurposeId","Supplier","TradeName")]
ingredients10<-file10[which(file10$IngredientsId!=""),c("DisclosureId","WellName","Latitude","Longitude","IngredientsId","IngredientCommonName","CASNumber","IngredientName","Purpose","PurposeId","Supplier","TradeName")]
ingredients11<-file11[which(file11$IngredientsId!=""),c("DisclosureId","WellName","Latitude","Longitude","IngredientsId","IngredientCommonName","CASNumber","IngredientName","Purpose","PurposeId","Supplier","TradeName")]
ingredients12<-file12[which(file12$IngredientsId!=""),c("DisclosureId","WellName","Latitude","Longitude","IngredientsId","IngredientCommonName","CASNumber","IngredientName","Purpose","PurposeId","Supplier","TradeName")]
ingredients13<-file13[which(file13$IngredientsId!=""),c("DisclosureId","WellName","Latitude","Longitude","IngredientsId","IngredientCommonName","CASNumber","IngredientName","Purpose","PurposeId","Supplier","TradeName")]
ingredients<-rbind(ingredients1,
ingredients2,
ingredients3,
ingredients4,
ingredients5,
ingredients6,
ingredients7,
ingredients8,
ingredients9,
ingredients10,
ingredients11,
ingredients12,
ingredients13)
#setwd("/Output/")
saveRDS(ingredients,"Output/ingredients.rds") #for later chemical curation
uniqueingredients<-unique(ingredients[,c("IngredientName","CASNumber")])
uniqueingredientspurposepairs<-unique(ingredients[,c("IngredientName","CASNumber","Purpose")])
saveRDS(uniqueingredientspurposepairs,"Output/uniqueingredientspurposepairs.rds")
uniquepurposes<-data.frame(unique(ingredients[,c("Purpose")]))
write.csv(uniqueingredients,"Output/uniqueingredients.csv")
write.csv(uniquepurposes,"Output/uniquepurposes.csv")
}
#load in existing function mappings and make list of unique curations
uniquepurposes<-read.csv("Output/uniquepurposes.csv")
#First deal with unique purposes
uniquepurposes<-data.frame(uniquepurposes[,2])
colnames(uniquepurposes)<-"Reported.Functional.Use"
uniquepurposes$index<-1:length(uniquepurposes$Reported.Functional.Use)
uniquepurposes2<-uniquepurposes %>%
mutate(individualpurposes = strsplit(as.character(Reported.Functional.Use), ",")) %>%
unnest(individualpurposes)
uniquepurposes2$Reported.Functional.Use<-uniquepurposes2$individualpurposes
uniquepurposes2<-uniquepurposes2[,!colnames(uniquepurposes2)=="individualpurposes"]
uniquepurposes_indexed<-uniquepurposes2 #maps back to reported purposes
#unique individual purposes
uniqueindividualpurposes<-data.frame(unique(uniquepurposes_indexed$Reported.Functional.Use))
colnames(uniqueindividualpurposes)<-"IndividualPurpose"
#Now try to curate uniqueindividualpurposes using the thousands of records already in Factotum
#Factotum is EPA's internal tool for curating information in the Chemicals and Products Database
#The most recent version of these data are available on the Download Data page of EPA's Chemical Exposure
#Knowledgebase (https://comptox.epa.gov/chemexpo/)
factotumfunction<-read.csv("Input/Factotum_bulk_functional_uses_20240615.csv")
uniquefunctioncurations<-unique(factotumfunction[,c("Harmonized.Functional.Use","Reported.Functional.Use")])
#remove incorrect mappings in factotum
uniquefunctioncurations<-uniquefunctioncurations[which(uniquefunctioncurations$Reported.Functional.Use!="Friction Reducer"),]
#now create case-insensitive versions of both that we want to match
uniquefunctioncurations$Reported.Functional.Useorig<-uniquefunctioncurations$Reported.Functional.Use
uniquefunctioncurations$Reported.Functional.Use<-trimws(tolower(uniquefunctioncurations$Reported.Functional.Use))
uniquefunctioncurations<-uniquefunctioncurations[which(uniquefunctioncurations$Harmonized.Functional.Use!=""),]
uniqueindividualpurposes$Reported.Functional.Use<-trimws(tolower(uniqueindividualpurposes$IndividualPurpose))
uniquestandardizedpurposes<-data.frame(unique(uniqueindividualpurposes$Reported.Functional.Use))
colnames(uniquestandardizedpurposes)<-"Reported.Functional.Use"
#merge
curatedpurposes<-left_join(uniquestandardizedpurposes,uniquefunctioncurations)
#make a dataframe of anything not curated using Factotum mappings
tocurate<-curatedpurposes[which(is.na(curatedpurposes$Harmonized.Functional.Use)),]
#Script-based curations: many of these are based on FracFocus functions described here:https://fracfocus.org/learn/what-is-fracturing-fluid-made-of
#acid: pH regulating agent
#biocide: Biocide
#carrier: Diluent
#breaker: Breaker_EPA
#stabilizer :Stabilizing agent
#cross-linker: Chemical reaction regulator
#friction reducer: Lubricating agent
#gel: Viscosity modifier
#iron control: Chelating agent
#no emulsifier: Demulsifier
#propping agent: Proppant (HF)
#scale inhibitor: Anti-scaling agent
#Surfactant: Surfactant
#hydrogen sulfide scavenger: H2S Scavenger (HF)
#oxygen scavenger: O2 Scavenger (HF)
#Paraffin inhibitor: Paraffin inhibitor (HF)
#diverter: Diverting agent (HF)
#tracer: Tracer (HF)
#blocking agent: Blocking agent (HF) #per research
#bridging agent: Bridging agent (HF) #per research
#flushing agent: Flushing agent (HF) #per research
#flowback agent: Flowback agent (HF) #per research
#emission control: Emission controlling agent #per research
#silt suspenders: Silt supending agent #per research Surfactant?
#Try to assign all visc mods (these are superceded by breakers and crosslinker assignments:
tocurate$Harmonized.Functional.Use[grepl("gel",tocurate$Reported.Functional.Use)]<-"Viscosity modifier"
tocurate$Harmonized.Functional.Use[grepl("guar",tocurate$Reported.Functional.Use)]<-"Viscosity modifier"
tocurate$Harmonized.Functional.Use[grepl("visco",tocurate$Reported.Functional.Use)]<-"Viscosity modifier"
tocurate$Harmonized.Functional.Use[grepl("rheolog",tocurate$Reported.Functional.Use)]<-"Viscosity modifier"
tocurate$Harmonized.Functional.Use[grepl("polymer",tocurate$Reported.Functional.Use)]<-"Viscosity modifier"
tocurate$Harmonized.Functional.Use[grepl("anionic polymer in emulsion form",tocurate$Reported.Functional.Use)]<-"Viscosity modifier"
tocurate$Harmonized.Functional.Use[grepl("flocc",tocurate$Reported.Functional.Use)]<-"Viscosity modifier"
tocurate$Harmonized.Functional.Use[grepl("vicosifier",tocurate$Reported.Functional.Use)]<-"Viscosity modifier"
tocurate$Harmonized.Functional.Use[grepl("visosifier",tocurate$Reported.Functional.Use)]<-"Viscosity modifier"
tocurate$Harmonized.Functional.Use[grepl("vixcosifier",tocurate$Reported.Functional.Use)]<-"Viscosity modifier"
tocurate$Harmonized.Functional.Use[grepl("geiling",tocurate$Reported.Functional.Use)]<-"Viscosity modifier"
tocurate$Harmonized.Functional.Use[grepl("xanthan",tocurate$Reported.Functional.Use)]<-"Viscosity modifier"
tocurate$Harmonized.Functional.Use[grepl("emulsion reducer/increases viscosity",tocurate$Reported.Functional.Use)]<-"Viscosity modifier"
tocurate$Harmonized.Functional.Use[grepl("viscosifier and fluid loss additive",tocurate$Reported.Functional.Use)]<-"Viscosity modifier"
tocurate$Harmonized.Functional.Use[grepl("transport",tocurate$Reported.Functional.Use) & grepl("additive",tocurate$Reported.Functional.Use) ]<-"Viscosity modifier" #per research
#dispersants
tocurate$Harmonized.Functional.Use[grepl("dispersant",tocurate$Reported.Functional.Use)]<-"Dispersing agent"
#carriers etc. (superceded by modifiers)
tocurate$Harmonized.Functional.Use[grepl("carrier",tocurate$Reported.Functional.Use)]<-"Diluent"
tocurate$Harmonized.Functional.Use[grepl("carry",tocurate$Reported.Functional.Use)]<-"Diluent"
tocurate$Harmonized.Functional.Use[grepl("base",tocurate$Reported.Functional.Use)]<-"Diluent"
tocurate$Harmonized.Functional.Use[grepl("fluid",tocurate$Reported.Functional.Use)]<-"Diluent"
tocurate$Harmonized.Functional.Use[grepl("career",tocurate$Reported.Functional.Use)]<-"Diluent"
tocurate$Harmonized.Functional.Use[grepl("water",tocurate$Reported.Functional.Use)]<-"Diluent"
tocurate$Harmonized.Functional.Use[grepl("carrer",tocurate$Reported.Functional.Use)]<-"Diluent"
tocurate$Harmonized.Functional.Use[grepl("div",tocurate$Reported.Functional.Use)]<-"Diverting agent (HF)"
tocurate$Harmonized.Functional.Use[grepl("penetrating",tocurate$Reported.Functional.Use)]<-"Diverting agent (HF)"
tocurate$Harmonized.Functional.Use[grepl("flush",tocurate$Reported.Functional.Use)]<-"Flushing agent (HF)"
tocurate$Harmonized.Functional.Use[grepl("line wash",tocurate$Reported.Functional.Use)]<-"Flushing agent (HF)"
tocurate$Harmonized.Functional.Use[grepl("foam",tocurate$Reported.Functional.Use)]<-"Foamant"
tocurate$Harmonized.Functional.Use[grepl("amphoteric foamer for water/acid",tocurate$Reported.Functional.Use)]<-"Foamant"
tocurate$Harmonized.Functional.Use[grepl("foam",tocurate$Reported.Functional.Use) & grepl("anti",tocurate$Reported.Functional.Use) ]<-"Defoamer"
tocurate$Harmonized.Functional.Use[grepl("freez",tocurate$Reported.Functional.Use)]<-"Anti-freeze agent"
tocurate$Harmonized.Functional.Use[grepl("deicing agent",tocurate$Reported.Functional.Use)]<-"Anti-freeze agent"
tocurate$Harmonized.Functional.Use[grepl("freez",tocurate$Reported.Functional.Use)]<-"Anti-freeze agent"
tocurate$Harmonized.Functional.Use[grepl("winter",tocurate$Reported.Functional.Use)]<-"Anti-freeze agent"
tocurate$Harmonized.Functional.Use[grepl("flow-back",tocurate$Reported.Functional.Use)]<-"Flowback agent (HF)"
tocurate$Harmonized.Functional.Use[grepl("flow back",tocurate$Reported.Functional.Use)]<-"Flowback agent (HF)"
tocurate$Harmonized.Functional.Use[grepl("flowback",tocurate$Reported.Functional.Use)]<-"Flowback agent (HF)"
tocurate$Harmonized.Functional.Use[grepl("flow assurance additive",tocurate$Reported.Functional.Use)]<-"Flow promoter"
tocurate$Harmonized.Functional.Use[grepl("flow enhancer",tocurate$Reported.Functional.Use)]<-"Flow promoter"
tocurate$Harmonized.Functional.Use[grepl("bridging",tocurate$Reported.Functional.Use)]<-"Diverting agent (HF)"
tocurate$Harmonized.Functional.Use[grepl("block",tocurate$Reported.Functional.Use)]<-"Blocking agent (HF)"
tocurate$Harmonized.Functional.Use[grepl("flush",tocurate$Reported.Functional.Use)]<-"Flushing agent (HF)"
tocurate$Harmonized.Functional.Use[grepl("solv",tocurate$Reported.Functional.Use)]<-"Solvent"
tocurate$Harmonized.Functional.Use[grepl("slovent",tocurate$Reported.Functional.Use)]<-"Solvent"
tocurate$Harmonized.Functional.Use[grepl("sovent",tocurate$Reported.Functional.Use)]<-"Solvent"
tocurate$Harmonized.Functional.Use[grepl("break",tocurate$Reported.Functional.Use)]<-"Breaker (HF)"
tocurate$Harmonized.Functional.Use[grepl("braker",tocurate$Reported.Functional.Use)]<-"Breaker (HF)"
tocurate$Harmonized.Functional.Use[grepl("beaker",tocurate$Reported.Functional.Use)]<-"Breaker (HF)"
tocurate$Harmonized.Functional.Use[grepl("trace",tocurate$Reported.Functional.Use)]<-"Tracer"
tocurate$Harmonized.Functional.Use[grepl("cross",tocurate$Reported.Functional.Use)]<-"Chemical reaction regulator"
tocurate$Harmonized.Functional.Use[grepl("xlink",tocurate$Reported.Functional.Use)]<-"Chemical reaction regulator"
tocurate$Harmonized.Functional.Use[grepl("x-li",tocurate$Reported.Functional.Use)]<-"Chemical reaction regulator"
tocurate$Harmonized.Functional.Use[grepl("activ",tocurate$Reported.Functional.Use)]<-"Chemical reaction regulator"
tocurate$Harmonized.Functional.Use[grepl("activ",tocurate$Reported.Functional.Use)]<-"Chemical reaction regulator"
tocurate$Harmonized.Functional.Use[grepl("corsslinker",tocurate$Reported.Functional.Use)]<-"Chemical reaction regulator"
tocurate$Harmonized.Functional.Use[grepl("accel",tocurate$Reported.Functional.Use)]<-"Chemical reaction regulator"
tocurate$Harmonized.Functional.Use[grepl("croslinking",tocurate$Reported.Functional.Use)]<-"Chemical reaction regulator"
tocurate$Harmonized.Functional.Use[grepl("enzyme",tocurate$Reported.Functional.Use)]<-"Chemical reaction regulator"
tocurate$Harmonized.Functional.Use[grepl("acitivator",tocurate$Reported.Functional.Use)]<-"Chemical reaction regulator"
tocurate$Harmonized.Functional.Use[grepl("resin acitvator",tocurate$Reported.Functional.Use)]<-"Chemical reaction regulator"
tocurate$Harmonized.Functional.Use[grepl("resin actavator",tocurate$Reported.Functional.Use)]<-"Chemical reaction regulator"
tocurate$Harmonized.Functional.Use[grepl("resin actiivator",tocurate$Reported.Functional.Use)]<-"Chemical reaction regulator"
tocurate$Harmonized.Functional.Use[grepl("resin hardener",tocurate$Reported.Functional.Use)]<-"Chemical reaction regulator"
tocurate$Harmonized.Functional.Use[grepl("croslinking",tocurate$Reported.Functional.Use)]<-"Chemical reaction regulator"
tocurate$Harmonized.Functional.Use[grepl("acticator",tocurate$Reported.Functional.Use)]<-"Chemical reaction regulator"
#Catalysts are a specific subclass of Chemical reaction regulator in the OECD dictionary
tocurate$Harmonized.Functional.Use[grepl("catylst",tocurate$Reported.Functional.Use)]<-"Catalyst"
tocurate$Harmonized.Functional.Use[grepl("catalyst",tocurate$Reported.Functional.Use)]<-"Catalyst"
tocurate$Harmonized.Functional.Use[grepl("conductivity endhancer",tocurate$Reported.Functional.Use)]<-"Conductive agent"
tocurate$Harmonized.Functional.Use[grepl("conductivity enhancer",tocurate$Reported.Functional.Use)]<-"Conductive agent"
tocurate$Harmonized.Functional.Use[grepl("polyelectrolyte",tocurate$Reported.Functional.Use)]<-"Conductive agent"
tocurate$Harmonized.Functional.Use[grepl("dust suppression",tocurate$Reported.Functional.Use)]<-"Dust suppressant"
tocurate$Harmonized.Functional.Use[grepl("polymer emulsifier",tocurate$Reported.Functional.Use)]<-"Emulsifier"
tocurate$Harmonized.Functional.Use[grepl("micro emulsion",tocurate$Reported.Functional.Use)]<-"Emulsifier"
tocurate$Harmonized.Functional.Use[grepl("microemulsifier",tocurate$Reported.Functional.Use)]<-"Emulsifier"
tocurate$Harmonized.Functional.Use[grepl("microemulsion",tocurate$Reported.Functional.Use)]<-"Emulsifier"
tocurate$Harmonized.Functional.Use[grepl("emulfifier",tocurate$Reported.Functional.Use)]<-"Emulsifier"
tocurate$Harmonized.Functional.Use[grepl("emuls",tocurate$Reported.Functional.Use)]<-"Emulsifier"
tocurate$Harmonized.Functional.Use[grepl("emulfifier",tocurate$Reported.Functional.Use)]<-"Emulsifier"
tocurate$Harmonized.Functional.Use[grepl("emulsi",tocurate$Reported.Functional.Use)]<-"Emulsifier"
tocurate$Harmonized.Functional.Use[grepl("emulsifier/dispersing agent",tocurate$Reported.Functional.Use)]<-"Emulsifier"
tocurate$Harmonized.Functional.Use[grepl("emulsio",tocurate$Reported.Functional.Use)]<-"Emulsifier"
tocurate$Harmonized.Functional.Use[grepl("emulsion",tocurate$Reported.Functional.Use)]<-"Emulsifier"
tocurate$Harmonized.Functional.Use[grepl("etching",tocurate$Reported.Functional.Use)]<-"Etching agent"
tocurate$Harmonized.Functional.Use[grepl("clean",tocurate$Reported.Functional.Use)]<-"Cleaning agent"
tocurate$Harmonized.Functional.Use[grepl("oxidiz",tocurate$Reported.Functional.Use)]<-"Oxidizing agent"
tocurate$Harmonized.Functional.Use[grepl("stabil",tocurate$Reported.Functional.Use)]<-"Stabilizing agent"
tocurate$Harmonized.Functional.Use[grepl("clay",tocurate$Reported.Functional.Use)]<-"Stabilizing agent"
tocurate$Harmonized.Functional.Use[grepl("stab",tocurate$Reported.Functional.Use)]<-"Stabilizing agent"
tocurate$Harmonized.Functional.Use[grepl("kcl",tocurate$Reported.Functional.Use)]<-"Stabilizing agent" #assume kcl etc is stabilizer per research
tocurate$Harmonized.Functional.Use[grepl("oilfield shale control",tocurate$Reported.Functional.Use)]<-"Stabilizing agent" # per research
tocurate$Harmonized.Functional.Use[grepl("shale inhibitor",tocurate$Reported.Functional.Use)]<-"Stabilizing agent" # per research
tocurate$Harmonized.Functional.Use[grepl("shale control",tocurate$Reported.Functional.Use)]<-"Stabilizing agent" # per research
tocurate$Harmonized.Functional.Use[grepl("shale swelling control",tocurate$Reported.Functional.Use)]<-"Stabilizing agent" # per research
tocurate$Harmonized.Functional.Use[grepl("kci substitute",tocurate$Reported.Functional.Use)]<-"Stabilizing agent" # per research
tocurate$Harmonized.Functional.Use[grepl("acid",tocurate$Reported.Functional.Use)]<-"pH regulating agent"
tocurate$Harmonized.Functional.Use[grepl("accid",tocurate$Reported.Functional.Use)]<-"pH regulating agent"
tocurate$Harmonized.Functional.Use[grepl("acic",tocurate$Reported.Functional.Use)]<-"pH regulating agent"
tocurate$Harmonized.Functional.Use[grepl("adiz",tocurate$Reported.Functional.Use)]<-"pH regulating agent"
tocurate$Harmonized.Functional.Use[grepl("buff",tocurate$Reported.Functional.Use)]<-"pH regulating agent"
tocurate$Harmonized.Functional.Use[grepl("phh adjusting agents",tocurate$Reported.Functional.Use)]<-"pH regulating agent"
tocurate$Harmonized.Functional.Use[grepl("biuffer",tocurate$Reported.Functional.Use)]<-"pH regulating agent"
tocurate$Harmonized.Functional.Use[grepl("hydrochloric",tocurate$Reported.Functional.Use)]<-"pH regulating agent"
tocurate$Harmonized.Functional.Use[grepl("hydrochloride",tocurate$Reported.Functional.Use)]<-"pH regulating agent"
tocurate$Harmonized.Functional.Use[grepl("ph ",tocurate$Reported.Functional.Use)]<-"pH regulating agent"
tocurate$Harmonized.Functional.Use[grepl("ph-",tocurate$Reported.Functional.Use)]<-"pH regulating agent"
tocurate$Harmonized.Functional.Use[grepl("hcl",tocurate$Reported.Functional.Use)]<-"pH regulating agent" #assume hcl is pH regulating agent per research
tocurate$Harmonized.Functional.Use[grepl("frict",tocurate$Reported.Functional.Use)]<-"Lubricating agent"
tocurate$Harmonized.Functional.Use[grepl("reducer",tocurate$Reported.Functional.Use)]<-"Lubricating agent"
tocurate$Harmonized.Functional.Use[grepl("lub",tocurate$Reported.Functional.Use)]<-"Lubricating agent"
tocurate$Harmonized.Functional.Use[grepl("friciton",tocurate$Reported.Functional.Use)]<-"Lubricating agent"
tocurate$Harmonized.Functional.Use[grepl("lub",tocurate$Reported.Functional.Use)]<-"Lubricating agent"
tocurate$Harmonized.Functional.Use[grepl("hvfr",tocurate$Reported.Functional.Use)]<-"Lubricating agent"
tocurate$Harmonized.Functional.Use[grepl("scale",tocurate$Reported.Functional.Use)]<-"Anti-scaling agent"
tocurate$Harmonized.Functional.Use[grepl("sacle",tocurate$Reported.Functional.Use)]<-"Anti-scaling agent"
tocurate$Harmonized.Functional.Use[grepl("salt",tocurate$Reported.Functional.Use) & grepl("inh",tocurate$Reported.Functional.Use) ]<-"Anti-scaling agent"
tocurate$Harmonized.Functional.Use[grepl("sale",tocurate$Reported.Functional.Use) & grepl("inh",tocurate$Reported.Functional.Use) ]<-"Anti-scaling agent"
tocurate$Harmonized.Functional.Use[grepl("sclae",tocurate$Reported.Functional.Use)]<-"Anti-scaling agent"
tocurate$Harmonized.Functional.Use[grepl("scaling",tocurate$Reported.Functional.Use)]<-"Anti-scaling agent"
tocurate$Harmonized.Functional.Use[grepl("scalant",tocurate$Reported.Functional.Use)]<-"Anti-scaling agent"
tocurate$Harmonized.Functional.Use[grepl("dcale inhibitor",tocurate$Reported.Functional.Use)]<-"Anti-scaling agent"
tocurate$Harmonized.Functional.Use[grepl("scal",tocurate$Reported.Functional.Use)]<-"Anti-scaling agent"
tocurate$Harmonized.Functional.Use[grepl("scal inhibitor",tocurate$Reported.Functional.Use)]<-"Anti-scaling agent"
tocurate$Harmonized.Functional.Use[grepl("svcale",tocurate$Reported.Functional.Use)]<-"Anti-scaling agent"
tocurate$Harmonized.Functional.Use[grepl("sufractant",tocurate$Reported.Functional.Use)]<-"Surfactant (surface active agent)"
tocurate$Harmonized.Functional.Use[grepl("surf",tocurate$Reported.Functional.Use)]<-"Surfactant (surface active agent)"
tocurate$Harmonized.Functional.Use[grepl("sludg",tocurate$Reported.Functional.Use)]<-"Surfactant (surface active agent)"
tocurate$Harmonized.Functional.Use[grepl("sufactant",tocurate$Reported.Functional.Use)]<-"Surfactant (surface active agent)" #per research
tocurate$Harmonized.Functional.Use[grepl("wettability",tocurate$Reported.Functional.Use)]<-"Surfactant (surface active agent)" #per research
tocurate$Harmonized.Functional.Use[grepl("silt suspending agent",tocurate$Reported.Functional.Use)]<-"Silt suspending agent (HF)" #per research
tocurate$Harmonized.Functional.Use[grepl("silt fines suspender",tocurate$Reported.Functional.Use)]<-"Silt suspending agent (HF)" #per research
tocurate$Harmonized.Functional.Use[grepl("silt suspender",tocurate$Reported.Functional.Use)]<-"Silt suspending agent (HF)" #per research
tocurate$Harmonized.Functional.Use[grepl("silt suspenders",tocurate$Reported.Functional.Use)]<-"Silt suspending agent (HF)" #per research
tocurate$Harmonized.Functional.Use[grepl("silt suspending agent",tocurate$Reported.Functional.Use)]<-"Silt suspending agent (HF)" #per research
tocurate$Harmonized.Functional.Use[grepl("prop",tocurate$Reported.Functional.Use)]<-"Proppant (HF)"
tocurate$Harmonized.Functional.Use[grepl("bulk",tocurate$Reported.Functional.Use)]<-"Proppant (HF)"
tocurate$Harmonized.Functional.Use[grepl("sand",tocurate$Reported.Functional.Use)]<-"Proppant (HF)"
tocurate$Harmonized.Functional.Use[grepl("ropp",tocurate$Reported.Functional.Use)]<-"Proppant (HF)"
tocurate$Harmonized.Functional.Use[grepl("peoppant",tocurate$Reported.Functional.Use)]<-"Proppant (HF)"
tocurate$Harmonized.Functional.Use[grepl("poppant",tocurate$Reported.Functional.Use)]<-"Proppant (HF)"
tocurate$Harmonized.Functional.Use[grepl("prppant",tocurate$Reported.Functional.Use)]<-"Proppant (HF)"
tocurate$Harmonized.Functional.Use[grepl("demul",tocurate$Reported.Functional.Use) ]<-"Demulsifier"
tocurate$Harmonized.Functional.Use[grepl("non",tocurate$Reported.Functional.Use) & grepl("emul",tocurate$Reported.Functional.Use) ]<-"Demulsifier"
tocurate$Harmonized.Functional.Use[grepl("non",tocurate$Reported.Functional.Use) & grepl("emus",tocurate$Reported.Functional.Use) ]<-"Demulsifier"
tocurate$Harmonized.Functional.Use[grepl("de-emulsifier",tocurate$Reported.Functional.Use) ]<-"Demulsifier"
tocurate$Harmonized.Functional.Use[grepl("demul",tocurate$Reported.Functional.Use) ]<-"Demulsifier"
tocurate$Harmonized.Functional.Use[grepl("emulsion preventer",tocurate$Reported.Functional.Use) ]<-"Demulsifier"
tocurate$Harmonized.Functional.Use[grepl("emulsion control",tocurate$Reported.Functional.Use) ]<-"Demulsifier"
tocurate$Harmonized.Functional.Use[grepl("emulsion pr",tocurate$Reported.Functional.Use) ]<-"Demulsifier"
tocurate$Harmonized.Functional.Use[grepl("non-emlusifier",tocurate$Reported.Functional.Use) ]<-"Demulsifier"
tocurate$Harmonized.Functional.Use[grepl("non emuilsifier",tocurate$Reported.Functional.Use) ]<-"Demulsifier"
tocurate$Harmonized.Functional.Use[grepl("non imulsifier",tocurate$Reported.Functional.Use) ]<-"Demulsifier"
tocurate$Harmonized.Functional.Use[grepl("non-ionic noneumulsifier",tocurate$Reported.Functional.Use) ]<-"Demulsifier"
tocurate$Harmonized.Functional.Use[grepl("non emsulifier",tocurate$Reported.Functional.Use) ]<-"Demulsifier"
tocurate$Harmonized.Functional.Use[grepl("emulson breaker",tocurate$Reported.Functional.Use) ]<-"Demulsifier"
tocurate$Harmonized.Functional.Use[grepl("emulsion breake",tocurate$Reported.Functional.Use) ]<-"Demulsifier"
tocurate$Harmonized.Functional.Use[grepl("iron",tocurate$Reported.Functional.Use)]<-"Chelating agent"
tocurate$Harmonized.Functional.Use[grepl("fe ",tocurate$Reported.Functional.Use)]<-"Chelating agent"
tocurate$Harmonized.Functional.Use[grepl("aluminum",tocurate$Reported.Functional.Use)]<-"Chelating agent"
tocurate$Harmonized.Functional.Use[grepl("chel",tocurate$Reported.Functional.Use)]<-"Chelating agent"
tocurate$Harmonized.Functional.Use[grepl("irion control additives",tocurate$Reported.Functional.Use)]<-"Chelating agent"
tocurate$Harmonized.Functional.Use[grepl("sequesterant",tocurate$Reported.Functional.Use)]<-"Chelating agent"
tocurate$Harmonized.Functional.Use[grepl("metal binder",tocurate$Reported.Functional.Use)]<-"Chelating agent"
tocurate$Harmonized.Functional.Use[grepl("sealer",tocurate$Reported.Functional.Use)]<-"Sealant (barrier)"
tocurate$Harmonized.Functional.Use[grepl("bioc",tocurate$Reported.Functional.Use)]<-"Biocide"
tocurate$Harmonized.Functional.Use[grepl("bacteri",tocurate$Reported.Functional.Use)]<-"Biocide"
tocurate$Harmonized.Functional.Use[grepl("microb",tocurate$Reported.Functional.Use)]<-"Biocide"
tocurate$Harmonized.Functional.Use[grepl("disinf",tocurate$Reported.Functional.Use)]<-"Biocide"
tocurate$Harmonized.Functional.Use[grepl("bleaching",tocurate$Reported.Functional.Use)]<-"Biocide"
tocurate$Harmonized.Functional.Use[grepl("sanit",tocurate$Reported.Functional.Use)]<-"Biocide"
tocurate$Harmonized.Functional.Use[grepl("antmircrobial",tocurate$Reported.Functional.Use)]<-"Biocide"
tocurate$Harmonized.Functional.Use[grepl("bactercide",tocurate$Reported.Functional.Use)]<-"Biocide"
tocurate$Harmonized.Functional.Use[grepl("biodice",tocurate$Reported.Functional.Use)]<-"Biocide"
tocurate$Harmonized.Functional.Use[grepl("bioicde",tocurate$Reported.Functional.Use)]<-"Biocide"
tocurate$Harmonized.Functional.Use[grepl("bioside",tocurate$Reported.Functional.Use)]<-"Biocide"
tocurate$Harmonized.Functional.Use[grepl("bocide",tocurate$Reported.Functional.Use)]<-"Biocide"
tocurate$Harmonized.Functional.Use[grepl("boicide",tocurate$Reported.Functional.Use)]<-"Biocide"
tocurate$Harmonized.Functional.Use[grepl("cide",tocurate$Reported.Functional.Use)]<-"Biocide"
tocurate$Harmonized.Functional.Use[grepl("disenfectant",tocurate$Reported.Functional.Use)]<-"Biocide"
tocurate$Harmonized.Functional.Use[grepl("bio control",tocurate$Reported.Functional.Use)]<-"Biocide"
tocurate$Harmonized.Functional.Use[grepl("bioide",tocurate$Reported.Functional.Use)]<-"Biocide"
tocurate$Harmonized.Functional.Use[grepl("antimicobial solution",tocurate$Reported.Functional.Use)]<-"Biocide"
tocurate$Harmonized.Functional.Use[grepl("antimicrovial solution",tocurate$Reported.Functional.Use)]<-"Biocide"
tocurate$Harmonized.Functional.Use[grepl("emission control",tocurate$Reported.Functional.Use)]<-"Emission controlling agent (HF)"
tocurate$Harmonized.Functional.Use[grepl("corros",tocurate$Reported.Functional.Use)]<-"Corrosion inhibitor"
tocurate$Harmonized.Functional.Use[grepl("corrison",tocurate$Reported.Functional.Use)]<-"Corrosion inhibitor"
tocurate$Harmonized.Functional.Use[grepl("corr inhib",tocurate$Reported.Functional.Use)]<-"Corrosion inhibitor"
tocurate$Harmonized.Functional.Use[grepl("cossosion",tocurate$Reported.Functional.Use)]<-"Corrosion inhibitor"
tocurate$Harmonized.Functional.Use[grepl("corriosion",tocurate$Reported.Functional.Use)]<-"Corrosion inhibitor"
tocurate$Harmonized.Functional.Use[grepl("corosion",tocurate$Reported.Functional.Use)]<-"Corrosion inhibitor"
tocurate$Harmonized.Functional.Use[grepl("cossosion",tocurate$Reported.Functional.Use)]<-"Corrosion inhibitor"
tocurate$Harmonized.Functional.Use[grepl("corossion",tocurate$Reported.Functional.Use)]<-"Corrosion inhibitor"
tocurate$Harmonized.Functional.Use[grepl("corrsion",tocurate$Reported.Functional.Use)]<-"Corrosion inhibitor"
tocurate$Harmonized.Functional.Use[grepl("block",tocurate$Reported.Functional.Use)]<-"Blocking agent"
tocurate$Harmonized.Functional.Use[grepl("o2",tocurate$Reported.Functional.Use) & grepl("scav",tocurate$Reported.Functional.Use) ]<-"O2 scavenger (HF)"
tocurate$Harmonized.Functional.Use[grepl("ox",tocurate$Reported.Functional.Use) & grepl("scav",tocurate$Reported.Functional.Use) ]<-"O2 scavenger (HF)"
tocurate$Harmonized.Functional.Use[grepl("oxygen savenger",tocurate$Reported.Functional.Use) ]<-"O2 scavenger (HF)"
tocurate$Harmonized.Functional.Use[grepl("oxygen scvanger",tocurate$Reported.Functional.Use) ]<-"O2 scavenger (HF)"
tocurate$Harmonized.Functional.Use[grepl("h2",tocurate$Reported.Functional.Use) & grepl("scav",tocurate$Reported.Functional.Use) ]<-"H2S scavenger (HF)"
tocurate$Harmonized.Functional.Use[grepl("sulf",tocurate$Reported.Functional.Use) & grepl("scav",tocurate$Reported.Functional.Use) ]<-"H2S scavenger (HF)"
tocurate$Harmonized.Functional.Use[grepl("h2s inhibitor",tocurate$Reported.Functional.Use) ]<-"H2S scavenger (HF)"
tocurate$Harmonized.Functional.Use[grepl("h2s neutrializer",tocurate$Reported.Functional.Use) ]<-"H2S scavenger (HF)"
tocurate$Harmonized.Functional.Use[grepl("h2s prevention",tocurate$Reported.Functional.Use) ]<-"H2S scavenger (HF)"
tocurate$Harmonized.Functional.Use[grepl("h2s treatment",tocurate$Reported.Functional.Use) ]<-"H2S scavenger (HF)"
tocurate$Harmonized.Functional.Use[grepl("hydrogen sulfide control",tocurate$Reported.Functional.Use)]<-"H2S scavenger (HF)"
tocurate$Harmonized.Functional.Use[grepl("prevent h2s formatio",tocurate$Reported.Functional.Use)]<-"H2S scavenger (HF)"
tocurate$Harmonized.Functional.Use[grepl("h2s inhibitor",tocurate$Reported.Functional.Use) ]<-"H2S scavenger (HF)"
tocurate$Harmonized.Functional.Use[grepl("prevent h2s formation",tocurate$Reported.Functional.Use) ]<-"H2S scavenger (HF)"
tocurate$Harmonized.Functional.Use[grepl("h2s neutrializer",tocurate$Reported.Functional.Use) ]<-"H2S scavenger (HF)"
tocurate$Harmonized.Functional.Use[grepl("h2s prevention",tocurate$Reported.Functional.Use) ]<-"H2S scavenger (HF)"
tocurate$Harmonized.Functional.Use[grepl("h2s treatment",tocurate$Reported.Functional.Use) ]<-"H2S scavenger (HF)"
tocurate$Harmonized.Functional.Use[grepl("h2s treatment",tocurate$Reported.Functional.Use) ]<-"H2S scavenger (HF)"
tocurate$Harmonized.Functional.Use[grepl("hydrogen sulfide control",tocurate$Reported.Functional.Use) ]<-"H2S scavenger (HF)"
tocurate$Harmonized.Functional.Use[grepl("liquid scavenger",tocurate$Reported.Functional.Use) ]<-"H2S scavenger (HF)"
tocurate$Harmonized.Functional.Use[grepl("paraf",tocurate$Reported.Functional.Use)]<-"Paraffin inhibitor (HF)"
tocurate$Harmonized.Functional.Use[grepl("parraf",tocurate$Reported.Functional.Use)]<-"Paraffin inhibitor (HF)"
tocurate$Harmonized.Functional.Use[grepl("parrifin",tocurate$Reported.Functional.Use)]<-"Paraffin inhibitor (HF)"
test<-tocurate[which(is.na(tocurate$Harmonized.Functional.Use)),]
#write.csv(test,"tocurate.csv")
#Fill in curated functions
k<-match(curatedpurposes$Reported.Functional.Use,tocurate$Reported.Functional.Use)
curatedpurposes$Harmonized.Functional.Use_new<-tocurate$Harmonized.Functional.Use[k]
j<-which(is.na(curatedpurposes$Harmonized.Functional.Use))
curatedpurposes$Harmonized.Functional.Use[j]<-curatedpurposes$Harmonized.Functional.Use_new[j]
curatedpurposes<-curatedpurposes[,c("Reported.Functional.Use","Harmonized.Functional.Use")]
#fix a few curations that may need updating from CPDat curations, or that weren't handled by the above logic
curatedpurposes$Harmonized.Functional.Use[which(curatedpurposes$Reported.Functional.Use=="polymer")]<-"Viscosity modifier"
curatedpurposes$Harmonized.Functional.Use[which(curatedpurposes$Reported.Functional.Use=="resin")]<-NA
curatedpurposes$Harmonized.Functional.Use[which(curatedpurposes$Reported.Functional.Use=="other")]<-NA # we just leave these NA
curatedpurposes$Harmonized.Functional.Use[which(curatedpurposes$Reported.Functional.Use=="miscellaneous")]<-NA # we just leave these NA
curatedpurposes$Harmonized.Functional.Use[which(curatedpurposes$Reported.Functional.Use=="additive")]<-NA # we just leave these NA
curatedpurposes$Harmonized.Functional.Use[which(curatedpurposes$Reported.Functional.Use=="various")]<-NA # we just leave these NA
curatedpurposes$Harmonized.Functional.Use[which(curatedpurposes$Reported.Functional.Use=="processing aid")]<-NA # we just leave these NA
curatedpurposes$Harmonized.Functional.Use[which(curatedpurposes$Reported.Functional.Use=="oil")]<-NA # we just leave these NA
curatedpurposes$Harmonized.Functional.Use[which(curatedpurposes$Reported.Functional.Use=="additives")]<-NA # we just leave these NA
curatedpurposes$Harmonized.Functional.Use[which(curatedpurposes$Reported.Functional.Use=="other additive")]<-NA # we just leave these NA
curatedpurposes$Harmonized.Functional.Use[which(curatedpurposes$Reported.Functional.Use=="unknown")]<-NA # we just leave these NA
curatedpurposes$Harmonized.Functional.Use[which(curatedpurposes$Reported.Functional.Use=="water treatment")]<-NA #this is ambiguous
curatedpurposes$Harmonized.Functional.Use[which(curatedpurposes$Reported.Functional.Use=="bleach")]<-"Biocide"
curatedpurposes$Harmonized.Functional.Use[which(curatedpurposes$Reported.Functional.Use=="bleaching agent")]<-"Biocide"
curatedpurposes$Harmonized.Functional.Use[which(curatedpurposes$Reported.Functional.Use=="paraffin")]<-"Paraffin inhibitor (HF)"
#these are multiple functions that are likely same product/ingredient, create duplicate with second curation
#These were curated as biocides or others; add scale inhibitors
new<-data.frame(c("scale inhibito & nitrate reducing bacteria","Anti-scaling agent"),
c("scale inhibitor & anbitbacterial agent","Anti-scaling agent"),
c("scale inhibitor & antibacterial agent","Anti-scaling agent"),
c("scale inhibitor & nitrate reducing bacteria","Anti-scaling agent"),
c("scale inhibitor & nitrate reducting bacteria","Anti-scaling agent"),
c("paraffin & scale additives","Anti-scaling agent"),
c("paraffin & scale additive","Anti-scaling agent"),
c("nitrate reducing bacteria & scale inhibitor","Anti-scaling agent"),
c("paraffin scale additives","Anti-scaling agent"),
c("scale paraffin inhibitor","Anti-scaling agent"),
c("paraffin scale additives","Anti-scaling agent"),
c("paraffin and scale additives","Anti-scaling agent"),
c("paraffin & scake additive","Anti-scaling agent"),
c("parraffin & scale additives","Anti-scaling agent"),
c("parrifin & scale additive","Anti-scaling agent"),
c("scale/paraffin inhibitor","Anti-scaling agent"),
c("paraffin & scale inhibitor","Anti-scaling agent"),
c("scale inihibitor & nitrate reducing bacteria","Anti-scaling agent"),
c("proppant/scale inhibitor","Anti-scaling agent"),
c("fracturing scale inhibitor/bacteria aid","Anti-scaling agent"),
c("scale/bacteria control","Anti-scaling agent"),
c("scale inhibitor/iron control","Anti-scaling agent"),
c("reduce iron/scale","Anti-scaling agent"),
c("corrosion/scale inhibitor","Anti-scaling agent"),
c("scale / corrosion inhibitor","Anti-scaling agent"),
c("scale inhibitor/non-emulsifier","Anti-scaling agent"),
c("scale/h2s scavenger","Anti-scaling agent"),
c("scale/paraffin inhibitor","Anti-scaling agent"),
#add surfactact
c("surfactant and biocide","Surfactant (surface active agent)"),
#add Demuls.
c("acid non-emulsifier and iron control","Demulsifier"),
#add foamant
c("foam booster/stabilizer","Foamant"),
c("surfactant & foamer","Foamant"),
c("surfactants & foamers","Foamant"),
c("surfacants & foamers","Foamant"),
c("surfactant & foamer","Foamant"),
c("surfactants & foamer","Foamant"),
c("surfactant blend/foamer","Foamant"),
c("surfactants (foamers)","Foamant"),
c("surfactants (foamers)","Foamant"),
c("surfacants & foamers","Foamant"),
#These were curated as Anti-scaling agent or other; add dispersant
c("scale inhibitor/polymer dispersant","Dispersing agent"),
c("scale inhibitor/polymer dispersant winterized","Dispersing agent"),
c("enduro-paraffin and dispersand/solvent","Dispersing agent"),
c("scale inhibitor/polymer dispersant","Dispersing agent"),
c("scale inhibitor/polymer dispersant winterized","Dispersing agent"),
c("emulsifier/dispersing agent","Dispersing agent"),
c("paraffin inhibitor/dispersant","Dispersing agent"),
#Add surfactant
c("biocide/surfactant","Surfactant (surface active agent)"),
c("furfactant and foamer","Surfactant (surface active agent)"),
c("surfactant and biocide","Surfactant (surface active agent)"),
c("corrosion inhibitor/surfactant","Surfactant (surface active agent)"),
c("non-emulsifier/surfactant","Surfactant (surface active agent)"),
c("non-emulsifier/ sufactant","Surfactant (surface active agent)"),
c("non-emulsifying surfactant","Surfactant (surface active agent)"),
c("surfactant/non-emulsifier","Surfactant (surface active agent)"),
c("non-emulsifier/ surfactant","Surfactant (surface active agent)"),
c("surfactant / non-emulsifier / flow back","Surfactant (surface active agent)"),
c("non-emulsifier/flowback surfactant","Surfactant (surface active agent)"),
#add breaker
c("breakers and breaker catalysts","Breaker (HF)"),
c("breakers and breaker catalyst","Breaker (HF)"),
c("breakers & breaker catalyst","Breaker (HF)"),
c("breaker and catalyst","Breaker (HF)"),
c("breaker and breaker catalyst","Breaker (HF)"),
c("breaker/oxidizer","Breaker (HF)"),
#others
c("bleaching agent/crosslinker","Chemical reaction regulator"),
c("breaker/biocide","Breaker (HF)"),
c("iron control/ ph buffer","pH regulating agent"),
c("acid inhibitor/iron control","pH regulating agent"),
c("acid non-emulsifier and iron control","Demulsifier"),
c("iron sulfide control/bio","Biocide"),
c("corrosion inhibitor/biocide","Biocide"),
c("surfactant / non-emulsifier / flow back","Flowback agent (HF)"),
c("non-emulsifier/flowback surfactant","Flowback agent (HF)"),
c("flowback/non-emulsifier","Flowback agent (HF)"),
c("flow back/non-emulsifier","Flowback agent (HF)"),
c("emulsifiers / viscosifiers","Viscosity modifier"),
c("corrosion inhibitor/iron control","Chelating agent"),
c("defoamer/binder","Binder"),
c("friction reducer/viscosifier","Viscosity modifier"),
c("friction reducer/viscosifer","Viscosity modifier"),
c("iron reducing agent / oxygen scavenger","Chelating agent"),
c("crosslinker/oxidizer","Chemical reaction regulator"),
c("crosslinker/buffer","Chemical reaction regulator"),
c("buffer/crosslinker","Chemical reaction regulator"),
c("crossliner/buffer","Chemical reaction regulator"),
c("paraffin/corrosion inhibitor","Corrosion inhibitor"),
c("acid / solvent","Solvent"),
c("citric acid/dilution","Diluent"),
c("acidizing/dilution","Diluent"),
c("carrier/acidizing","Diluent"),
c("acid retarder / viscosifier","Viscosity modifier"),
c("acid/diverting agent","Diverting agent (HF)"),
c("clay control/activator","Chemical reaction regulator"),
c("clay control / stabilizers","Chemical reaction regulator"),
c("foam booster/stabilizer","Foamant"),
c("foamer/surfactant","Foamant"),
c("non-elmulsifier/surfactant","Demulsifier"),
c("non-elmulsifier/surfactant","Demulsifier"),
c("surfactant/clay control","Stabilizing agent"),
c("emulsifier/surfactant","Emulsifier"),
c("surfactant/ flow back aid","Flowback agent (HF)"),
c("surfactant/flo back aid","Flowback agent (HF)"),
c("surfactant blend/foamer","Foamant"),
c("clay control/surfactant","Stabilizing agent"),
c("surfactant and clay inhibitor blend","Stabilizing agent"),
#add two func
c("borate crosslinker - stabilizer - ph buffer","Stabilizing agent"),
c("borate crosslinker - stabilizer - ph buffer","Chemical reaction regulator"))
new<-t(new)
colnames(new)<-c("Reported.Functional.Use","Harmonized.Functional.Use")
curatedpurposes<-rbind(curatedpurposes,new)
#these are multiple function records that are likely overreporting or errors
curatedpurposes$Harmonized.Functional.Use[which(curatedpurposes$Reported.Functional.Use=="propping agent. acid corrosion inhibitor. friction reducer. biocide. microbiocide. microbiocide. blocking agent. clean perforations")]<-NA
curatedpurposes$Harmonized.Functional.Use[which(curatedpurposes$Reported.Functional.Use=="paraffin/ne/scale inh./bio/h2s scav.")]<-NA
write.csv(curatedpurposes,"Output/curatedpurposes_forexamination.csv") # for ease of examination for QA
#forQA
test<-data.frame(table(curatedpurposes$Harmonized.Functional.Use))
#Match the data back to the original reported purposes
temp1<-uniquepurposes
colnames(uniquepurposes)[1]<-"Purpose"
temp2<-left_join(uniquepurposes,uniquepurposes_indexed)
temp2$Reported.Functional.Use<-trimws(tolower(temp2$Reported.Functional.Use)) #we standardized these before curating
finalcuratedpurposes<-left_join(temp2,curatedpurposes)
#save final data
saveRDS(finalcuratedpurposes,"output/final_curated_purposes.RDS")