-
Notifications
You must be signed in to change notification settings - Fork 0
/
brain-to-cypher.R
79 lines (53 loc) · 3.18 KB
/
brain-to-cypher.R
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
rm(list=ls())
# P. Setup -------------------------------------------------------------------
date = "20210625" # for grabbing files. choose most rrecent or preferred brain export dump
# initialize vector for storing export object names of interest.
export <- c("data.in", "data.out")
## create a directory to throw warnings and notes into
dir.create("warnings")
# set path to data in and data out.
## in my case, this data is private so need to specify a path.
## data.dir should be the parent directory for subdirectories c(data, data-raw).
## if dirs do not exist, will create.
data.in <- "/Users/jburnett/OneDrive - DOI/research/bbs_utility/neo4j-brain-data/data-raw/"
data.out <- "/Users/jburnett/OneDrive - DOI/research/bbs_utility/neo4j-brain-data/data/"
# 0. Packages ----------------------------------------------------------------
library(rjson); library(jsonlite)
library(tidyverse); library(janitor)
# 1. Data In -----------------------------------------------------------------
## Import the raw json files as exported from TheBrain
source("R/import_json_from_brain.R")
# 2. Munge and QA/QC ------------------------------------------------------------
## Lightly munges the links and nodes data frames.
source("R/munge_brain.R")
# 4. Extract questions ------------------------------------------------------
source("R/make_questions_table.R")
# 5. Create table of people,orgs, and affiliations -----------------------------------------------
source("R/make_people_table.R")
# 6. Extract the interpreted and paraphrased responses -------------------------------------------------------------------------
source("R/jlb_para_euts_tables.R")
# 7. Add the Question Names to Links that have "Response:..." tag -----------------------------------------------
source("R/question_to_resp.R")
# 8. People, affiliations to responses ------------------------------------
source("R/people_aff_to_resp.R")
# 9. Resp to Resp ---------------------------------------------------------
source("R/resp_to_resp.R")
# 10. Final munge of data frames for cypher -------------------------------
source("R/munge_tables_for_cypher.R")
# 11. Make a single, big ass DF --------------------------------------------------
source("R/make_single_df.R")
## This isnt going to do what I want i think. I should figure out how to export the relationships from neo4j
# 12. Export useful dfs --------------------------------------------------
source("R/export_files_for_neo4j.R")
# NOTES -------------------------------------------------------------------
# 99. Tests -------------------------------------------------------------------
## Need to make sure we have accounted for all the people, types, etc and that
## the only remaining links are Response -> Response
if(any(links$ThoughtIdA %in% people$PersonId))warning("oops")
if(any(links$ThoughtIdA %in% people$OrganizationId))warning("oops")
if(any(links$ThoughtIdA %in% people$AffiliationId))warning("oops")
if(any(links$ThoughtIdB %in% people$PersonId))warning("oops")
if(any(links$ThoughtIdB %in% people$OrganizationId))warning("oops")
if(any(links$ThoughtIdB %in% people$AffiliationId))warning("oops")
# 999.END RUN -----------------------------------------------------------------
print(export)