Commit f31be21
authored
Merge pull request #5 from robert-mcdermott/win-encoding-bug
Fixed Issue #4 (charmap) issue on Windows systems
Fix Windows encoding issues in knowledge graph visualization
## Issue
Windows users were experiencing UnicodeEncodeError when generating knowledge graphs with certain input files. The error occurred during HTML generation with the message: 'charmap' codec can't encode characters in position 263607-263621: character maps to <undefined>
## Root Cause
The PyVis library was using the system's default encoding when writing HTML files. On Windows, this is typically 'cp1252' (Windows-1252), which has limited Unicode support compared to UTF-8 that's used on Mac/Linux systems.
## Fix
Modified the [_save_and_modify_html](cci:1://file:///Users/rmcdermo/mycode/ai-knowledge-graph/src/knowledge_graph/visualization.py:324:0-362:44) function to:
1. Use PyVis's internal HTML generation capabilities instead of letting it write to a file
2. Directly access the generated HTML content in memory
3. Write the file ourselves with explicit UTF-8 encoding
This bypasses the encoding issue completely by taking control of the file writing process with proper UTF-8 handling, ensuring consistent behavior across all operating systems.
## Testing
Confirmed working on both Mac OS and Windows environments with the same input data.3 files changed
+11
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
324 | 324 | | |
325 | 325 | | |
326 | 326 | | |
327 | | - | |
328 | | - | |
| 327 | + | |
| 328 | + | |
329 | 329 | | |
330 | | - | |
331 | | - | |
332 | | - | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
333 | 336 | | |
334 | 337 | | |
335 | 338 | | |
| |||
341 | 344 | | |
342 | 345 | | |
343 | 346 | | |
344 | | - | |
| 347 | + | |
345 | 348 | | |
346 | 349 | | |
347 | 350 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments