Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more READMEs for example projects. #242

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion trustfall/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ There is no local data ingestion step in this demo — we don't ETL the data int

The [feeds](feeds/) demo project runs Trustfall queries over the feeds of PCGamer and Wired magazines.

It downloads the feed contents (as XML data files), then parses those files and runs Trustfall queries on them.
It downloads the feed contents as XML data files, then parses those files and runs Trustfall queries on them.
135 changes: 135 additions & 0 deletions trustfall/examples/feeds/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# Querying RSS and Atom feeds

This demo project runs Trustfall queries over the feeds of PCGamer and Wired magazines.

It downloads the feed contents as XML data files, then parses those files and runs Trustfall queries on them.

- [Example: Find articles containing game reviews in PCGamer](#example-find-articles-containing-game-reviews-in-pcgamer)
- [Example: Extract all links and titles as a list from each feed](#example-extract-all-links-and-titles-as-a-list-from-each-feed)

## Example: Find articles containing game reviews in PCGamer

Query: ([link](example_queries/game_reviews.ron))
```graphql
{
Feed {
title {
content @filter(op: "has_substring", value: ["$feed"])
}

entry_: entries {
title_: title {
content @filter(op: "regex", value: ["$title_pattern"])
@output
}

links {
link: href @output
}

content {
body @output
}
}
}
}
```
with arguments `{ "feed": "PCGamer" }`.

To run it:
```
$ cargo run --example feeds query ./examples/feeds/example_queries/game_reviews.ron
< ... cargo output ... >

{
"entry_body": "\n \n <article>\n <p>There is a Super Mario Bros film hitting cinemas this week, and the question on everyone&apos;s lips seems to be: will it ruin my childhood? I hope not! But childhood destroying or not (Chris Pratt <a href=\"https://www.hollywoodreporter.com/movies/movie-news/chris-pratt-super-mario-bros-movie-mario-voice-reaction-premiere-1235365581/\"><u>reckons</u></a> you&apos;re safe, but he would say that), the critical response is surprisingly varied, [...]",
"entry_link": "https://www.pcgamer.com/super-mario-bros-movie-chris-pratt-doesnt-ruin-the-movie-but-its-still-not-that-great",
"entry_title_content": "Super Mario Bros movie review round-up: 'Chris Pratt doesn't ruin the movie' but it's still not that great"
}
```

## Example: Extract all links and titles as a list from each feed

Query: ([link](example_queries/feed_links.ron))
```graphql
{
Feed {
id @output
feed_type @output

title_: title {
content @output
content_type @output
}

entries @fold {
title {
entry_title: content @output
}
links {
entry_link: href @output
}
}
}
}
```

To run it:
```
$ cargo run --example feeds query ./examples/feeds/example_queries/feed_links.ron
< ... cargo output ... >

{
"entry_link": [
"https://www.pcgamer.com/my-favorite-multiplayer-game-of-2023-so-far-is-basically-competitive-hitman",
"https://www.pcgamer.com/youtuber-bypasses-chatgpts-ethical-constraints-to-make-it-generate-working-windows-95-keys",
"https://www.pcgamer.com/there-will-be-a-chirper-for-sure-in-cities-skylines-2-says-colossal-order-ceo",
[...]
"https://www.pcgamer.com/what-diablo-4-classes-did-we-love-the-most-during-the-beta",
"https://www.pcgamer.com/samsungs-chip-boffins-couldnt-help-but-tell-chatgpt-their-secrets",
"https://www.pcgamer.com/acer-predator-x32-fp-review"
],
"entry_title": [
"My favorite multiplayer game of 2023 so far is basically competitive Hitman",
"YouTuber bypasses ChatGPT's ethical constraints to make it generate working Windows 95 keys",
"'There will be a Chirper, for sure' in Cities: Skylines 2, says Colossal Order CEO",
[...]
"Diablo 4 class impressions: Sorcerers are OP and Barbarians need more time in the gym",
"Samsung's chip boffins couldn't help but tell ChatGPT their secrets",
"Acer Predator X32 FP"
],
"feed_type": "RSS2",
"id": "6ea975addf5d7fbd1a01263fc9b99152",
"title_content": "PCGamer latest",
"title_content_type": "text/plain"
}

{
"entry_link": [
"https://www.wired.com/story/trump-mug-shot-privacy/",
"https://www.wired.com/story/one-citys-escape-plan-from-rising-seas/",
"https://www.wired.com/story/overwatch-2-support-hero-lifeweaver/",
"https://www.wired.com/story/best-photo-printing-services/",
"https://www.wired.com/story/platforms-design-ux-affordances/",
[...]
"https://www.wired.com/review/system76-pangolin-linux-laptop/",
"https://www.wired.com/story/large-language-model-phishing-scams/",
"https://www.wired.com/story/burning-man-climate-death-spiral/"
],
"entry_title": [
"A Mug Shot Could Play Right Into Trump’s Hands",
"What Would Strategic Relocation from Charleston Look Like?",
"The Latest ‘Overwatch 2’ Hero Is Going to Start a Class War",
"8 Best Photo Printing Services (2023): Tips, Print Quality, and More",
"There’s No Such Thing as a One-Size-Fits-All Web",
[...]
"System76 Pangolin Review: A 15-Inch Linux Laptop for the Masses",
"Brace Yourself for a Tidal Wave of ChatGPT Email Scams",
"Can Burning Man Pull Out of Its Climate Death Spiral?"
],
"feed_type": "RSS2",
"id": "6e6444830b6d094a37e5f2b0bac76c8",
"title_content": "Feed: All Latest",
"title_content_type": "text/plain"
}
```
11 changes: 7 additions & 4 deletions trustfall/examples/feeds/example_queries/feed_links.ron
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ InputQuery (
feed_type @output

title_: title {
src @output
content @output
content_type @output
}

links_: links @fold {
title @output
href @output
entries @fold {
title {
entry_title: content @output
}
links {
entry_link: href @output
}
}
}
}"#,
Expand Down
3 changes: 3 additions & 0 deletions trustfall/examples/weather/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ This demo project queries meteorogical data from the US Aviation Weather Center:

The data is delivered as a CSV file from the following link: [https://aviationweather.gov/adds/dataserver_current/current/metars.cache.csv](https://aviationweather.gov/adds/dataserver_current/current/metars.cache.csv)

- [Example: Find the temperature, dewpoint, wind, and clouds in Boston](#example-find-the-temperature-dewpoint-wind-and-clouds-in-boston)
- [Example: Which weather stations are reporting 25+ knot winds and gusty conditions?](#example-which-weather-stations-are-reporting-25-knot-winds-and-gusty-conditions)

## Example: Find the temperature, dewpoint, wind, and clouds in Boston

Query: ([link](example_queries/boston_weather.ron))
Expand Down