Skip to content

Commit c9d9a63

Browse files
authored
Merge pull request #9 from codefuse-ai/add-tuto
[feat][doc] Add JavaScript analysis tutorial & add some extensions to be installed when in codespaces
2 parents 178b442 + e503f76 commit c9d9a63

File tree

3 files changed

+3004
-9
lines changed

3 files changed

+3004
-9
lines changed

.devcontainer/devcontainer.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
{
22
"image": "ghcr.io/lonrun/codefuse-query-tutorial:0.5",
33
"hostRequirements": {
4-
"cpus": 4
4+
"cpus": 4
55
},
66
"customizations": {
7-
"codespaces": {
8-
"openFiles": ["tutorial/README.md"]
9-
}
7+
"codespaces": {
8+
"openFiles": [
9+
"tutorial/README.md"
10+
]
11+
},
12+
// Configure properties specific to VS Code.
13+
"vscode": {
14+
// Add the IDs of extensions you want installed when the container is created.
15+
"extensions": [
16+
"ms-toolsai.jupyter",
17+
"MS-CEINTL.vscode-language-pack-zh-hans",
18+
"CodeFuse-Query.codefuse-query-extension"
19+
]
20+
}
1021
}
1122
}

tutorial/README.md

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,85 @@
1-
## CodeQuery使用教程
1+
## CodeFuse-Query使用教程
22

3-
### 使用Github Codespaces 来体验CodeQuery分析能力
3+
### 使用Github Codespaces 来体验CodeFuse-Query分析能力
4+
5+
### Jupyter kernel for CodeFuse-query 介绍
6+
7+
Jupyter kernel for CodeFuse-query 是 Jupyter 的一个特定内核,它为 Jupyter 环境提供了与 CodeFuse-query 相关的交互式功能。该内核允许用户在 Jupyter Notebook 中编写和执行 Godel 脚本,用于抽取、查询代码数据。此外,它还支持编写 Python 代码,以便对查询到的数据进行更深入的数据可视化和数据后处理操作。这里我们使用这个内核编写 Jupyter Notebook,用来进行 CodeFuse-Query 教程的学习和实践。
48

59
#### 步骤
610

7-
- 在项目主页切换到目标分支
811
- 创建 Codespaces,依次点击 Code -> Codespaces,在当前分支创建一个 Codespaces
912
- 创建后,打开该 Codespaces,加载完成后,切换至项目 tutorial/notebook 目录下
10-
- 选择示例下的 jupyter notebook 分析教程,即可开始体验
13+
- 选择示例下的 Jupyter Notebook 分析教程,即可开始体验
1114

1215
#### 注意
13-
- 打开jupyter页面之后,如果是第一次加载容器,你还需要配置教程所使用的内核,在右上角 “选择内核”弹出框中,依次选择 “Juypter Kernel...” -> “Godel Kernel” 即可。
16+
17+
在打开 Jupyter 页面之后,如果是第一次加载容器,你还需要配置教程所使用的 `Jupyter kernel for CodeFuse-query`。在右上角的 "选择内核" 弹出框中,依次选择 "Jupyter Kernel..." -> "Godel Kernel"。
18+
19+
#### Kernel 用法
20+
##### 设置要查询的 COREF database
21+
22+
使用 `%db /path/to/db` 魔法命令来设置COREF db路径,内核会读取这个值来进行query查询,比如:
23+
24+
```bash
25+
%db ./db
26+
```
27+
28+
> tips: 还可以用`!`来运行一些有用的bash命令,比如查看Sparrow CLI是否存在:
29+
30+
```rust
31+
!which sparrow
32+
```
33+
34+
##### Godel 查询
35+
36+
设置好db路径后可以直接写Godel脚本,Jupyter kernel会创建临时文件来保存当前运行的Godel脚本并调用`sparrow query run`命令来进行查询,结果返回以HTML格式显示:
37+
38+
39+
```rust
40+
// Write your query and run in the notebook
41+
// ...
42+
```
43+
44+
45+
`%db` 魔法命令可以写在 Godel 脚本的第一行:
46+
47+
48+
```rust
49+
%db ./db
50+
// Write your query and run in the notebook
51+
// ...
52+
```
53+
54+
55+
可以通过 `%%save_to` cell魔法命令保存**上一次运行成功**的 query 结果到一个JSON文件,具体用法:
56+
```bash
57+
%%save_to PATH - save the query result to a JSON file.
58+
59+
This cell magic will save the Sparrow query result to a file.
60+
61+
Example:
62+
%%save_to /path/to/file.json
63+
```
64+
65+
比如:
66+
```bash
67+
%%save_to ./query.json
68+
```
69+
70+
##### 运行 Python 代码
71+
72+
可以通过 `%%python` 或者 `%python` 来运行 Python 代码,比如:
73+
74+
```python
75+
%%python
76+
import pandas as pd
77+
data = pd.read_json('./query.json')
78+
data.sort_values('cmplx', ascending=False, inplace=True)
79+
top_10 = data.head(10)
80+
print(top_10)
81+
```
82+
83+
```python
84+
%python print('hello')
85+
```

0 commit comments

Comments
 (0)