-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,56 @@ | ||
# hakurei | ||
|
||
## Namuwiki Parser | ||
|
||
Dump download: https://mu-star.net/wikidb | ||
|
||
### Extract Category | ||
|
||
Most articles have categories. | ||
|
||
```rs | ||
fn main() { | ||
let js = load_dump(); | ||
extract_category(js); | ||
} | ||
``` | ||
|
||
#### (Example) Find By Category | ||
|
||
If you want to fetch `Article` rather than `Title`, modify the code appropriately. | ||
|
||
```rs | ||
fn find_by_category<'a>(js: &'a Vec<Article>, what: &str) -> Vec<&'a str> { | ||
let mut result: Vec<&str> = Vec::new(); | ||
|
||
for x in js { | ||
let category = x.categories(); | ||
|
||
if category.iter().any(|x| x.starts_with(what)) { | ||
result.push(&x.title); | ||
} | ||
} | ||
|
||
result.sort_by(|a, b| a.cmp(b)); | ||
|
||
result | ||
} | ||
``` | ||
|
||
### Title indexing | ||
|
||
Before using, you must create title index file. | ||
|
||
```rs | ||
fn main() { | ||
create_title_index(); | ||
} | ||
``` | ||
|
||
```rs | ||
fn main() { | ||
let mut index = TitleIndex::load(); | ||
|
||
println!("{}", index.get("하쿠레이 신사").unwrap().text); | ||
} | ||
``` |