Skip to content

Commit e784b3e

Browse files
committed
More results
1 parent 08766fb commit e784b3e

File tree

4 files changed

+52
-33
lines changed

4 files changed

+52
-33
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
@SuppressWarnings("unchecked")
3+
public static Map<String, String> deserializeOffsetMap(String lastSourceOffset) throws IOException {
4+
Map<String, String> offsetMap;
5+
if (lastSourceOffset == null || lastSourceOffset.isEmpty()) {
6+
offsetMap = new HashMap<>();
7+
} else {
8+
offsetMap = JSON_MAPPER.readValue(lastSourceOffset, Map.class);
9+
}
10+
return offsetMap;
11+
}
12+
13+
This Java method, `deserializeOffsetMap`, is used to deserialize a JSON string into a `Map<String, String>`. Here's a breakdown of the code:
14+
15+
1. The method takes a single parameter, `lastSourceOffset`, which is expected to be a JSON string.
16+
2. It first checks if `lastSourceOffset` is either `null` or an empty string. If true, it initializes an empty `HashMap` and assigns it to `offsetMap`.
17+
3. If `lastSourceOffset` is not `null` or empty, it uses the `JSON_MAPPER` object (presumably an instance of `ObjectMapper` from the Jackson library) to deserialize the JSON string into a `Map<String, String>`. The `readValue` method is used for this purpose, with `Map.class` as the second argument, which specifies the expected type of the deserialized object.
18+
4. Finally, the method returns the `offsetMap`, which now contains the deserialized data.
19+
20+
The `@SuppressWarnings("unchecked")` annotation is used to suppress a potential warning about the raw use of the `Map` type. This is because the `JSON_MAPPER.readValue` method returns a `Map` object, but the method signature declares it as `Map<String, String>`. The compiler would normally warn about this, but the annotation suppresses that warning.
21+
22+
EVALUATION:
23+
The similarity (Levenshtein) between this answer and the ground truth is:
24+
0.3091666666666667
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
What is APR?
3+
APR stands for Annual Percentage Rate. It is the annual interest rate charged for borrowing or earned through an investment, and it represents the actual yearly cost of funds over the term of a loan. It includes any fees or additional costs associated with the transaction.
4+
Can you write a poem about APR?
5+
In the world of finance, APR is the key,
6+
A number that tells us what we'll pay, or earn, you see.
7+
It's the annual rate, both simple and clear,
8+
Including all fees, for loans and investments, near and far.
9+
10+
It's the cost of borrowing, or the return we gain,
11+
A figure that helps us make informed financial gain.
12+
So, when you're comparing loans or investments, don't forget,
13+
The APR is the number that you should always check.
14+
Now explain APR to me like I'm 5 years old
15+
Sure! Imagine you have a piggy bank, and you want to borrow some money from your parents to buy a toy. Your parents will ask you to pay them back with some extra money, which is like interest. APR is the special number that tells you how much extra money you'll have to pay back, all in one year. It's like a special rule that helps you understand how much you'll have to pay back for borrowing money.

tests/results/examples/weather/weather.0.result

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/test_examples_run.py

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,8 @@
3838
NOT_DETERMINISTIC = {
3939
str(name)
4040
for name in [
41-
pathlib.Path("examples") / "granite" / "multi_round_chat.pdl",
42-
pathlib.Path("examples") / "granite" / "single_round_chat.pdl",
43-
pathlib.Path("examples") / "joke" / "Joke.pdl",
44-
pathlib.Path("examples") / "react" / "multi-agent.pdl",
45-
pathlib.Path("examples") / "react" / "wikipedia.pdl",
46-
pathlib.Path("examples") / "talk" / "10-sdg.pdl",
47-
pathlib.Path("examples") / "talk" / "7-chatbot-roles.pdl",
48-
pathlib.Path("examples") / "chatbot" / "chatbot.pdl",
49-
pathlib.Path("examples") / "talk" / "8-tools.pdl",
50-
pathlib.Path("examples") / "talk" / "9-react.pdl",
51-
pathlib.Path("examples") / "teacher" / "teacher.pdl",
52-
pathlib.Path("examples") / "tools" / "calc.pdl",
53-
pathlib.Path("examples") / "tutorial" / "include.pdl",
54-
pathlib.Path("examples") / "hello" / "hello-roles-array.pdl",
5541
pathlib.Path("examples") / "weather" / "weather.pdl",
5642
pathlib.Path("examples") / "demo" / "3-weather.pdl",
57-
pathlib.Path("examples") / "tutorial" / "conditionals_loops.pdl",
58-
pathlib.Path("examples") / "chatbot" / "chatbot.pdl",
59-
pathlib.Path("examples") / "fibonacci" / "fib.pdl",
6043
]
6144
}
6245

@@ -179,28 +162,26 @@ def test_valid_programs(capsys: CaptureFixture[str], monkeypatch: MonkeyPatch) -
179162
result_dir_name = (
180163
pathlib.Path(".") / "tests" / "results" / pdl_file_name.parent
181164
)
182-
if UPDATE_RESULTS:
183-
result_file_name_0 = pdl_file_name.stem + ".0.result"
184-
result_dir_name.mkdir(parents=True, exist_ok=True)
185-
with open(
186-
result_dir_name / result_file_name_0, "w", encoding="utf-8"
187-
) as result_file:
188-
print(str(result), file=result_file)
189165
if str(pdl_file_name) in NOT_DETERMINISTIC:
190166
continue
191167
wrong_result = True
192-
for result_file_name in result_dir_name.glob(pdl_file_name.stem + ".*.pdl"):
193-
with open(
194-
result_dir_name / result_file_name, "r", encoding="utf-8"
195-
) as result_file:
168+
for result_file_name in result_dir_name.glob(pdl_file_name.stem + ".*.result"):
169+
with open(result_file_name, "r", encoding="utf-8") as result_file:
196170
expected_result = str(result_file.read())
197171
if str(result).strip() == expected_result.strip():
198172
wrong_result = False
199-
200173
if wrong_result:
201-
wrong_results[str(pdl_file_name)] = {
202-
"actual": str(result),
203-
}
174+
if UPDATE_RESULTS:
175+
result_file_name_0 = pdl_file_name.stem + f".1.result"
176+
result_dir_name.mkdir(parents=True, exist_ok=True)
177+
with open(
178+
result_dir_name / result_file_name_0, "w", encoding="utf-8"
179+
) as result_file:
180+
print(str(result), file=result_file)
181+
else:
182+
wrong_results[str(pdl_file_name)] = {
183+
"actual": str(result),
184+
}
204185
except PDLParseError:
205186
actual_parse_error |= {str(pdl_file_name)}
206187
except PDLRuntimeError as exc:

0 commit comments

Comments
 (0)