[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-111544":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":14,"stars7d":16,"stars30d":17,"stars90d":15,"forks30d":15,"starsTrendScore":18,"compositeScore":19,"rankGlobal":9,"rankLanguage":9,"license":20,"archived":21,"fork":21,"defaultBranch":22,"hasWiki":23,"hasPages":21,"topics":24,"createdAt":9,"pushedAt":31,"updatedAt":32,"readmeContent":33,"aiSummary":34,"trendingCount":15,"starSnapshotCount":15,"syncStatus":35,"lastSyncTime":36,"discoverSource":37},111544,"PID-to-Knowledge-Graph","ScottDuncanAI\u002FPID-to-Knowledge-Graph","ScottDuncanAI","P&ID to Knowledge Graph: a Claude skill that turns P&ID PDFs (digital or scanned) into a process knowledge graph of flow, instruments and control loops.",null,"Python",317,67,6,1,0,27,101,9,70.98,"MIT License",false,"main",true,[25,26,27,28,29,30],"chemical-engineering","claude-skills","isa-5-1","knowledge-graph","pid","process-engineering","2026-11-08 20:33:02","2026-11-23 15:51:20","# P&ID to Knowledge Graph\n\nBy Scott Duncan. Reach me on [LinkedIn](https:\u002F\u002Fwww.linkedin.com\u002Fin\u002Fs-r-duncan\u002F) or at [scottduncanai.com](https:\u002F\u002Fscottduncanai.com\u002F).\n\n**Turn P&ID drawings into a process knowledge graph that an LLM can reason over.**\n\n`pid-to-kg` is a [Claude skill](https:\u002F\u002Fcode.claude.com\u002Fdocs\u002Fen\u002Fskills) that reads piping and instrumentation diagrams (P&IDs) and PFDs from PDF and builds a knowledge graph of the process. The PDFs can be digital (exported from CAD) or scanned. The graph captures:\n\n- **Process flow:** what is upstream and downstream of every tank, pump, valve and pipe segment.\n- **Measurement:** which instrument measures which variable, and exactly where it sits in the flow.\n- **Control:** control loops from sensor through controller to final element, including I\u002FP relays, cascades, interlocks and VFD drives.\n\nThe output is meant to be one layer of a chemical-manufacturing **context layer**. An LLM application can query it to answer questions such as \"what feeds this clarifier?\", \"which transmitters sit downstream of P-101?\" or \"what does FIC-0502 manipulate?\" from the drawings themselves.\n\n## Quick start\n\nNo programming is needed. You need [Claude Code](https:\u002F\u002Fcode.claude.com\u002Fdocs\u002Fen\u002Foverview) (the desktop app or the terminal version) and [Python](https:\u002F\u002Fwww.python.org\u002Fdownloads\u002F) 3.10 or newer. Python 3.12 is the best choice: on 3.13 and later the skill still works, but without the text-recognition (OCR) cross-check and automatic page orientation.\n\n**1. Download the skill.** On this page, click the green **Code** button, then **Download ZIP**. Unzip the file.\n\n**2. Install it.** In the unzipped folder, open `skills` and copy the `pid-to-kg` folder into your personal Claude skills folder:\n\n| System | Skills folder |\n|---|---|\n| Windows | `C:\\Users\\\u003Cyour user name>\\.claude\\skills\\` |\n| macOS | `\u002FUsers\u002F\u003Cyour user name>\u002F.claude\u002Fskills\u002F` |\n\nIf the `skills` folder doesn't exist yet, create it. The `.claude` folder is hidden by default: in Windows File Explorer use **View → Show → Hidden items**, and in macOS Finder press **Cmd + Shift + .** to show it.\n\n**3. Add your P&IDs.** Make a new folder for the project and put your P&ID PDF in it. Open that folder in Claude Code: in the desktop app, start a new Code session and choose the folder.\n\nNo P&IDs at hand? My [public chemical manufacturing datasets](https:\u002F\u002Fgithub.com\u002FScottDuncanAI\u002Fpublic-chemical-manufacturing-datasets#pids) repo lists public P&ID sets from real permitted facilities, with the page numbers where the drawings are. Both digital and scanned sets are included.\n\n**4. Ask Claude to convert them.** For example:\n\n> Convert `haile.pdf` into a knowledge graph. The P&IDs are on pages 47–60.\n\nThe skill loads by itself; there is no need to name it. The first time, Claude installs the Python packages it needs, and it asks your permission before running commands. It then reads every sheet in detail, so a large drawing set takes a while. Claude may ask a question along the way, such as which revision to use when a PDF holds two versions of the same drawing. When it is done, it reports what it found and what remains uncertain.\n\n**5. Check the graph by asking questions.** The best test is to ask about things you can verify on the drawings:\n\n> Name all the equipment upstream of the clarifier.\n>\n> What sensor measures the flow into TK-101, and where exactly is it?\n>\n> What does FIC-0502 control, and what valve does it move?\n\nThe results are saved in `work\u002F\u003Cplant name>\u002Fkg\u002F` inside your project folder. `summary.md` is a readable overview of the whole plant, and `qa_report.md` lists anything Claude could not confirm.\n\n## How it works\n\n![How the skill works: your P&ID PDF, Claude reads it, build and check, ask questions](docs\u002Fhow-it-works.svg)\n\n**Claude reads the drawings; Python scripts do everything else.** Recognising symbols and tracing lines needs visual judgement, so that part is Claude's. Preparing pages, building the graph and checking it are routine, so tested scripts do them the same way every time.\n\n### 1. Preparing the pages\n\nA script first looks at every page and works out what kind of drawing it is. Digital and scanned P&IDs need different handling:\n\n| Page type | How to recognise it | What the skill does |\n|---|---|---|\n| **Digital, searchable text** | Exported from CAD; you can select the text in a PDF viewer | Renders the page straight from the vector data, so lines stay sharp at any zoom. The exact text in the PDF is used to cross-check the tags Claude reads. |\n| **Digital, outlined text** | Looks digital, but the text can't be selected: every letter was drawn as shapes. Common in CAD exports. | Renders from the vector data at high resolution. Since there is no text to pull out, OCR (text recognition) reads the tags for the cross-check. |\n| **Scanned** | Each page is a picture of a paper drawing | Takes the scanned image at its original resolution, enlarges it up to 2.5×, and boosts the contrast so faded lines and small text stand out. OCR reads the tags for the cross-check. Low-resolution scans are flagged, because small text may be lost. |\n| **Scanned with OCR text** | A scan with a searchable text layer added | Handled like a scan. The added text layer is only used as a hint, since it often contains errors. |\n\nThen, for every page:\n- **Orientation:** the page is turned so the text is upright, since drawings are often stored sideways in a PDF.\n- **Resolution:** chosen from the size of the drawing's text, so the smallest tags stay legible.\n- **Tiles:** the sheet is cut into overlapping tiles, and blank tiles (empty margins, border lines) are skipped.\n\n### 2. Claude reads each sheet\n\n- Claude reads the whole sheet first, then every tile up close.\n- It records equipment, pipe runs, valves, instruments, signal lines and off-page connectors.\n- Each item gets the place on the sheet where it was found and a confidence level. Anything unreadable is marked as such, never guessed.\n- Each sheet is saved to its own file before the next one starts, so large drawing sets don't overload Claude.\n\n### 3. Building and checking the knowledge graph\n\nThe scripts turn Claude's readings into one connected knowledge graph:\n- **Process flow:** each pipe is split into segments between its valves and fittings, and off-page connectors link the sheets, so flow can be traced upstream or downstream across the whole plant.\n- **Measurement:** every instrument is attached to the exact pipe segment or vessel it measures.\n- **Control:** loops are assembled from the instrument tags (per ISA-5.1) and the signal lines, from sensor to controller to valve or drive.\n\nA QA report then lists anything doubtful: a sensor with no location, an off-page connector with no partner, a tag OCR saw that Claude didn't record. Claude re-checks each one on the drawing and rebuilds until the report is clean.\n\n### 4. Asking questions\n\n- `summary.md` is a readable overview to give an LLM as context.\n- `graph.json` holds the full graph for any tool to read.\n- `graph.duckdb` is a small database file for precise queries. Nothing needs a server.\n- Every item records the sheet it came from, so any answer can be traced back to the drawing.\n\n## Outputs\n\n| File | What it is |\n|---|---|\n| `summary.md` | A readable overview of the plant: equipment-level flow, equipment, instruments with their locations, control loops and off-page links. This is the file to give an LLM as context. |\n| `qa_report.md` | Errors, warnings and notes, each pointing to the part of the drawing to re-check |\n| `graph.json` | The complete graph (schema: [`graph.schema.json`](skills\u002Fpid-to-kg\u002Freferences\u002Fschema\u002Fgraph.schema.json)) |\n| `graph.duckdb` | The same graph as a [DuckDB](https:\u002F\u002Fduckdb.org) database file, for SQL queries, including recursive upstream and downstream searches |\n\nFor larger projects, the graph can also be exported to Neo4j or to GraphML (for yEd, Gephi or NetworkX). Ask Claude to do it.\n\nThe node and edge types are described in [`references\u002Fontology.md`](skills\u002Fpid-to-kg\u002Freferences\u002Fontology.md). Equipment and instruments also carry the closest [DEXPI](https:\u002F\u002Fdexpi.org) class, the industry standard for exchanging P&ID data.\n\n## Repository layout\n\n```\nskills\u002Fpid-to-kg\u002F\n  SKILL.md                    workflow Claude follows\n  references\u002F                 extraction procedure, ISA-5.1 guide, symbol guide, ontology, JSON schemas\n  scripts\u002F                    probe, render, hints, build, query, export, eval, crop\n  scripts\u002Fpidkg\u002F              library: models, ISA parsing, builder, loops, QA, storage, summary\ndocs\u002F                         README diagram\ntests\u002F                        pytest suite with a synthetic two-sheet plant and synthetic PDFs\n```\n\n## Limitations\n\n- **Extraction quality depends on legibility.** Low-resolution scans lose small text. Unreadable items are recorded as such, never guessed.\n- **Loops come from ISA tag numbers and drawn signal lines.** Logic that lives only in control narratives or cause-and-effect charts is not on the P&ID and is not captured.\n- **Line direction is taken from arrows and equipment logic.** Edges whose direction had to be inferred are marked `flow_direction: inferred`.\n- **The DEXPI mapping is informative.** It is not a certified DEXPI export.\n\n## Development\n\n```bash\npip install -e \".[dev]\"\npytest\npython skills\u002Fpid-to-kg\u002Fscripts\u002Fbuild_kg.py --write-schemas   # after changing pidkg\u002Fmodels.py\n```\n\n## Disclaimer\n\nThe graph is machine-extracted from drawings. It must be reviewed by a qualified engineer before it is used for design, operations, management of change, or safety studies such as HAZOP or LOPA.\n\n## License\n\nMIT. See [LICENSE](LICENSE).\n","该项目是一个面向化工流程工程的Claude技能，可将P&ID（管道及仪表流程图）PDF文件（含数字版与扫描版）自动解析并构建为结构化知识图谱。核心功能包括识别设备、管道、仪表与控制回路，精确建模上下游流程关系、测量点位置及完整控制链（含I\u002FP转换器、串级、联锁等）。技术上融合OCR、PDF文本\u002F布局分析与领域规则推理，输出可供大语言模型直接查询的RDF\u002FJSON-LD格式图谱。适用于化工设计审查、操作培训、智能运维问答、安全合规核查等需从图纸快速提取工艺逻辑的工业场景。",2,"2026-11-24 04:41:06","CREATED_QUERY"]