Skip to content

Commit 1624a2e

Browse files
Merge pull request #96 from terminusdb/OJS-Python-English-Fixes
Ojs python english fixes
2 parents 74c721e + b7aacff commit 1624a2e

File tree

5 files changed

+75
-75
lines changed

5 files changed

+75
-75
lines changed

getting_started/python-client/lesson_2.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Lesson 2 - Importing a CSV file into the database
22

3-
> **_NOTE:_** from version 10.1.0 the cli command is `tdbpy` instead of `terminusdb`
3+
> **_NOTE:_** from version 10.1.0 the CLI command is `tdbpy` instead of `terminusdb`
44
55
## The `tdbpy importcsv` Command
66

7-
In this lesson, we will try to import a CSV file with the `tdbpy importcsv` command. It provide a very simple way to import a CSV with less manual effort. There are a few things that you can control with the `tdbpy importcsv` command, like setting the separator character, how to handle NAs and linking columns using a key columns etc. For more complicated data handling, a Python script will be needed and we will demonstrate that the next lesson: [Importing data form Python script](lesson_3.md)
7+
In this lesson, we will import a CSV file with the `tdbpy importcsv` command. It provides a very simple way to import a CSV. There are a few things that you can control with the `tdbpy importcsv` command, such as setting the separator character, how to handle NAs, and linking columns using a key columns. For more complicated data handling, a Python script is needed and we will demonstrate that in lesson 5: [Importing data form Python script](lesson_3.md)
88

9-
To see all the available options in `tdbpy importcsv`:
9+
The example below enables you to see all the available options in `tdbpy importcsv`:
1010

1111
```
1212
$ tdbpy importcsv --help
@@ -16,21 +16,21 @@ Usage: tdbpy importcsv [OPTIONS] CSV_FILE [KEYS]...
1616
read_csv() options. Options like chunksize, sep etc
1717
1818
Options:
19-
--classname TEXT Customize the class name that the data from the
20-
CSV will be import as
19+
--classname TEXT Customize the class name that data from the
20+
CSV will be imported as
2121
22-
--chunksize INTEGER Large files will be load into database in
22+
--chunksize INTEGER Large files will load into the database in
2323
chunks, size of the chunks [default: 1000]
2424
25-
--schema Specify if schema to be updated if existed,
25+
--schema Specify if the schema is to be updated if it exists,
2626
default False
2727
2828
--na [skip|optional|error] Specify how to handle NAs: 'skip' will skip
2929
entries with NAs, 'optional' will make all
3030
properties optional in the database, 'error'
31-
will just throw an error if there's NAs
31+
will just throw an error if there are NAs
3232
33-
--id TEXT Specify column to be used as ids instead of
33+
--id TEXT Specify the column to be used as ids instead of
3434
generated ids
3535
3636
-e, --embedded TEXT Specify embedded columns
@@ -43,7 +43,7 @@ Options:
4343

4444
## Importing CSV
4545

46-
Continue working with the phonebook example. We can now try to import the [Employees.csv](Employees.csv) file. Which looks like this:
46+
We will continue working with the phonebook example. We will import the [Employees.csv](Employees.csv) file. Which looks like this:
4747

4848
| Employee id | Name | Title | Team | Manager |
4949
| ----------- | -------------- | ------------------- | ----------- | ----------- |
@@ -52,7 +52,7 @@ Continue working with the phonebook example. We can now try to import the [Emplo
5252
| 003 | Alanah Bloggs | Frontend Developer | IT | 004 |
5353
| 004 | Fabian Dalby | Web Service Manager | IT | |
5454

55-
As you see there are `Employee id` which are used as a key to link the `Manager` field to the person that is the manager of that employee.
55+
As you see there is `Employee id` used as a key to link to the `Manager` field showing who the employee's manager is.
5656

5757
To link them, we must first install the `pandas` library.
5858
```sh
@@ -68,7 +68,7 @@ Schema object EmployeesFromCSV created with Employees.csv being imported into da
6868
Records in Employees.csv inserted as type EmployeesFromCSV into database with specified ids.
6969
```
7070

71-
We have imported the CSV file with the class as `EmployeesFromCSV` you can see that there is a new class object in `schema.py` that is created as well:
71+
We have imported the CSV file with the class as `EmployeesFromCSV`. There is a new class object in `schema.py` that was created along with the import:
7272

7373
```python
7474
class EmployeesFromCSV(DocumentTemplate):
@@ -86,7 +86,7 @@ $ tdbpy alldocs
8686
[{'@id': 'EmployeesFromCSV/001', '@type': 'EmployeesFromCSV', 'employee_id': '001', 'name': 'Destiny Norris', 'team': 'Marketing', 'title': 'Marketing Manager'}, {'@id': 'EmployeesFromCSV/002', '@type': 'EmployeesFromCSV', 'employee_id': '002', 'manager': 'EmployeesFromCSV/001', 'name': 'Darci Prosser', 'team': 'Marketing', 'title': 'Creative Writer'}, {'@id': 'EmployeesFromCSV/003', '@type': 'EmployeesFromCSV', 'employee_id': '003', 'manager': 'EmployeesFromCSV/004', 'name': 'Alanah Bloggs', 'team': 'IT', 'title': 'Frontend Developer'}, {'@id': 'EmployeesFromCSV/004', '@type': 'EmployeesFromCSV', 'employee_id': '004', 'name': 'Fabian Dalby', 'team': 'IT', 'title': 'Web Service Manager'}]
8787
```
8888

89-
In [later chapters](lesson_5.md) we will also learn how to query this data and/ or export data into CSV ([or using Singer.io to export data into other data products](https://github.com/terminusdb/terminusdb-tutorials/tree/master/google_sheets/README.md)).
89+
In [chapter 5](lesson_5.md) we will learn how to query this data and/ or export data into CSV.
9090

9191
---
9292

getting_started/python-client/lesson_3.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Lesson 3 - Importing data form Python script
1+
# Lesson 3 - Importing Data From a Python Script
22

3-
> **_NOTE:_** from version 10.1.0 the cli command is `tdbpy` instead of `terminusdb`
3+
> **_NOTE:_** from version 10.1.0 the CLI command is `tdbpy` instead of `terminusdb`
44
5-
In last lesson, we have import the [Employees.csv](Employees.csv) with the `tdbpy` commmand. It auto generate the schema for you and pipe in the data form the CSV. Let's check the [schema.py](schema.py), you can see the schema that is generate from the CSV:
5+
In the last lesson we imported [Employees.csv](Employees.csv) using the `tdbpy importcsv` commmand. It autogenerated the schema and piped in the data from the CSV. If we check the [schema.py](schema.py) we can see the schema that was generated from the CSV:
66

77
```python
88
class EmployeesFromCSV(DocumentTemplate):
@@ -13,7 +13,7 @@ class EmployeesFromCSV(DocumentTemplate):
1313
title: Optional[str]
1414
```
1515

16-
It is not the same as the one we have planned in [Lesson 1](lesson_1.md):
16+
You may noticed that the schema is not the same as the one we have talked about in [Lesson 1](lesson_1.md):
1717

1818
```python
1919
class Employee(DocumentTemplate):
@@ -27,26 +27,26 @@ class Employee(DocumentTemplate):
2727
title: str
2828
```
2929

30-
because we have some data in the [Contact.csv](Contact.csv). Fetching data from different CSVs and combining them according to our schema requires more customization and it can be done by creating a Python script with the [TerminusDB Python Client](https://github.com/terminusdb/terminusdb-client-python).
30+
This is because we had data in the [Contact.csv](Contact.csv). Fetching data from different CSVs and matching them to our schema requires a little more customization. This can be done by creating a Python script using the [TerminusDB Python Client](https://github.com/terminusdb/terminusdb-client-python).
3131

3232
## Creating the Python script
3333

34-
Let's start a new `.py` file [insert_data.py](insert_data.py). You can copy and paste the one we have in this repo or build one yourself. We will explain the one we have so you have an idea what it does.
34+
Let's start a new `.py` file [insert_data.py](insert_data.py). You can copy and paste the one in this repo or build one yourself. We'll explain the example script so you understand what it does.
3535

36-
In the first half of the script, we have to manage and import the data form CSV. In Python there is the [`csv` standard library](https://docs.python.org/3/library/csv.html) where can aid reading of CSV files. Go ahead and import that:
36+
In the first half of the script, we have to manage and import the data form CSV. In Python there is the [`csv` standard library](https://docs.python.org/3/library/csv.html) that helps reading of CSV files. Go ahead and import that:
3737

3838
```python
3939
import csv
4040
```
4141

42-
Also we need to import `WOQLClient` which is the client that communitcate with the TerminusDB/ TerminusCMS and `schema.py`:
42+
We also need to import `WOQLClient` which is the client that communitcates with the TerminusDB/ TerminusCMS and `schema.py`:
4343

4444
```python
4545
from terminusdb_client import WOQLClient
4646
from schema import *
4747
```
4848

49-
At the top of the script, we prepare a few empty dictionaries to hold the data, we use dictionaries cause the keys can be the `Employees id` for easy mapping:
49+
At the top of the script, we prepare a few empty dictionaries to hold the data, we use dictionaries because the keys can be the `Employees id` for easy mapping:
5050

5151
```python
5252
employees = {}
@@ -55,7 +55,7 @@ addresses = {}
5555
managers = {}
5656
```
5757

58-
The goal is to populate the `employees` dictionaries with the `Employee` objects. To help, we also need `contact_numbers` to hold the contact numbers while reading the `Contact.csv`. The rest of the information in `Contact.csv` will be used to construct `Address` objects and stored in `addresses`. `managers` is used to store the employee id in the `Manager` column in the `Employees.csv`. We store the id at first and make the linking later cause the manager of that employee may have not been "created" yet.
58+
The goal is to populate the `employees` dictionaries with the `Employee` objects. To help, we also need `contact_numbers` to hold the contact numbers while reading the `Contact.csv`. The rest of the information in `Contact.csv` will be used to construct `Address` objects and stored in `addresses`. `managers` is used to store the employee id in the `Manager` column in `Employees.csv`. We store the id at first and make the linking later because the manager of that employee may have not been "created" yet.
5959

6060
Then we go head and read the CSVs and do the corresponding data managing:
6161

@@ -89,25 +89,25 @@ with open("Employees.csv") as file:
8989
managers[row[0]] = row[4]
9090
```
9191

92-
Last, we have to make the manager links:
92+
Finally, we have to make the manager links:
9393

9494
```python
9595
for emp_id, man_id in managers.items():
9696
if man_id:
9797
employees[emp_id].manager = employees[man_id]
9898
```
9999

100-
Now, the `employees` dictionary should be populated with the `Employee` objects that is ready to be insert into the database.
100+
Now, the `employees` dictionary should be populated with the `Employee` objects, ready to be inserted into the database.
101101

102102
## Using the Python client
103103

104-
The next step is the insert all `Employees` into the database. But before, we need to create a client with our endpoint:
104+
The next step is the insert all `Employees` into the database. But before that, we need to create a client with our endpoint:
105105

106106
```python
107107
client = WOQLClient("http://127.0.0.1:6363/")
108108
```
109109

110-
Then we will connect the client to our database. If you are connecting locally and use default setting, just provide the database you are connecting to:
110+
Then we will connect the client to our database. If you are connecting locally and use the default setting, just provide the database you are connecting to:
111111

112112
```python
113113
client.connect(db="getting_started")
@@ -123,20 +123,20 @@ client.insert_document(list(employees.values()), commit_msg="Adding 4 Employees"
123123

124124
## Running the script
125125

126-
Do back to our terminal, we can run the script. Make sure you are in a Python environment that has `terminusdb-client` installed.
126+
Go back to the terminal and run the script. Make sure you are in a Python environment that has `terminusdb-client` installed.
127127

128128
```
129129
$ python insert_data.py
130130
```
131131

132-
To check if the data is insert correctly, we can use the `tdbpy alldocs` command again:
132+
To check the data has been inserted correctly, use the `tdbpy alldocs` command:
133133

134134
```
135135
$ tdbpy alldocs --type Employee
136136
```
137137

138-
Or if the data is on TerminusCMS, you can check it in the [TerminusCMS dashboard](https://dashboard.terminusdb.com/)
138+
If you used TerminusCMS check it's there in the [TerminusCMS dashboard](https://dashboard.terminusdb.com/)
139139

140140
---
141141

142-
[Move on to Lesson 4 - Update and import new data that links to old data](lesson_4.md)
142+
[Lesson 4 - Update and import new data that links to old data](lesson_4.md)

getting_started/python-client/lesson_5.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# Lesson 5 - Query on the database and get result back as CSV or DataFrame
1+
# Lesson 5 - Query the database and get results back as a CSV or DataFrame
22

3-
> **_NOTE:_** from version 10.1.0 the cli command is `tdbpy` instead of `terminusdb`
3+
> **_NOTE:_** from version 10.1.0 the CLI command is `tdbpy` instead of `terminusdb`
44
5-
In the past lessons, we have learnt how to build schema and import data. Now the database has all the data we wanted, what we will do after is to get information out of the data we have in the database.
5+
In previous lessons we learnt how to build schema and import data. Now the database has all the data we wanted. Now we want to get information out of the database.
66

7-
In this lesson, we will learn how to query the database, get the information that we wanted. Then export either to a CSV for later use or to import as Pandas DataFrames for further investigation.
7+
In this lesson we will learn how to query the database, get the information we need, and export either to a CSV or as a Pandas DataFrames.
88

9-
## Query data with `tdbpy` Command
9+
## Query Data with `tdbpy` Command
1010

11-
The most direct way to query on data and export it as CSV is to use the `tdbpy` command.
11+
The most direct way to query data and export it as CSV is to use the `tdbpy` command.
1212

13-
If you are planning to export all documents in a particular type. You can simply use the `tdbpy exportcsv` command. Let's have a look a the command:
13+
If you are planning to export all documents of a particular type. You can simply use the `tdbpy exportcsv` command. Let's have a look at the command:
1414

1515
```
1616
$ tdbpy exportcsv --help
@@ -36,9 +36,9 @@ Now let's try to export all `Employee` to a file named `exported_employees.csv`
3636

3737
`$ tdbpy exportcsv --filename exported_employees.csv Employee`
3838

39-
Inspect [exported_employees.csv](exported_employees.csv) and it look just as what we expected. All 5 employees information is there.
39+
We'll quickly inspect [exported_employees.csv](exported_employees.csv) and can see it looks good. Information for all 5 employees is there.
4040

41-
But now, we want to only want the members of the IT team to be export in a CSV, we will have to do a bit of query. Let's try using the `-q` options with `tdbpy alldocs`
41+
Say we want to export only members of the IT team in a CSV, we have to do a bit of query. Let's try using the `-q` option with `tdbpy alldocs`
4242

4343
```
4444
$ tdbpy alldocs --type Employee -q team=it
@@ -51,22 +51,22 @@ It's a bit hard to see so we are going to export it to [a CSV](exported_it_team.
5151

5252
## Query data in Python script
5353

54-
If we want to do something more complicated, for example, see which team has longer names in average. We may have to export the result to a Pandas Dataframe and do more investigation. Let's have a look at [query_data.py](query_data.py).
54+
If we want to do something more complicated, for example see which team has longer names in average. We can export the result to a Pandas Dataframe and do more investigation. Let's have a look at [query_data.py](query_data.py).
5555

56-
We can make use of the magic function `result_to_df` to convert a result json to a Pandas DataFrame:
56+
We can make use of the magic function `result_to_df` to convert the JSON results to a Pandas DataFrame:
5757

5858
```python
5959
from terminusdb_client.woqldataframe import result_to_df
6060
```
6161

62-
Querying would be done by `query_document`, you will have to provide a template json that has `@type` and the specific requirement(s) (in our case, `"team": "it"` or `"team": "marketing"`).
62+
Querying can be done by `query_document`, you will have to provide a template JSON that has `@type` and the specific requirement(s) (in our case, `"team": "it"` or `"team": "marketing"`).
6363

6464
```python
6565
team_it_raw = client.query_document({"@type": "Employee", "team": "it"})
6666
team_marketing_raw = client.query_document({"@type": "Employee", "team": "marketing"})
6767
```
6868

69-
We can use `reault_to_df` to get DataFrames:
69+
We can use `reault_to_df` to get the DataFrames:
7070

7171
```python
7272
team_it = result_to_df(team_it_raw)
@@ -93,4 +93,4 @@ I won't spoil the results for you, you have to find it out yourself :-)
9393

9494
---
9595

96-
[Move on to Lesson 6 - Version control: time travel, branching and rebase](lesson_6.md)
96+
[Lesson 6 - Version control: time travel, branching and rebase](lesson_6.md)

0 commit comments

Comments
 (0)