plasmapdf 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- plasmapdf-0.0.1/.gitignore +4 -0
- plasmapdf-0.0.1/.idea/.gitignore +8 -0
- plasmapdf-0.0.1/.idea/inspectionProfiles/Project_Default.xml +33 -0
- plasmapdf-0.0.1/.idea/inspectionProfiles/profiles_settings.xml +6 -0
- plasmapdf-0.0.1/.idea/misc.xml +7 -0
- plasmapdf-0.0.1/.idea/modules.xml +8 -0
- plasmapdf-0.0.1/.idea/plasmapdf.iml +10 -0
- plasmapdf-0.0.1/.idea/vcs.xml +6 -0
- plasmapdf-0.0.1/.idea/workspace.xml +81 -0
- plasmapdf-0.0.1/LICENSE.txt +9 -0
- plasmapdf-0.0.1/PKG-INFO +174 -0
- plasmapdf-0.0.1/README.md +150 -0
- plasmapdf-0.0.1/plasmapdf/__about__.py +4 -0
- plasmapdf-0.0.1/plasmapdf/__init__.py +3 -0
- plasmapdf-0.0.1/plasmapdf/models/PdfDataLayer.py +453 -0
- plasmapdf-0.0.1/plasmapdf/models/__init__.py +0 -0
- plasmapdf-0.0.1/plasmapdf/models/types.py +319 -0
- plasmapdf-0.0.1/plasmapdf/utils/__init__.py +0 -0
- plasmapdf-0.0.1/plasmapdf/utils/utils.py +64 -0
- plasmapdf-0.0.1/pyproject.toml +68 -0
- plasmapdf-0.0.1/tests/__init__.py +3 -0
- plasmapdf-0.0.1/tests/test_packaging.py +152 -0
- plasmapdf-0.0.1/tests/test_pdf_data_layer.py +76 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<component name="InspectionProjectProfileManager">
|
|
2
|
+
<profile version="1.0">
|
|
3
|
+
<option name="myName" value="Project Default" />
|
|
4
|
+
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
|
5
|
+
<option name="ignoredPackages">
|
|
6
|
+
<value>
|
|
7
|
+
<list size="20">
|
|
8
|
+
<item index="0" class="java.lang.String" itemvalue="transformers" />
|
|
9
|
+
<item index="1" class="java.lang.String" itemvalue="sklearn" />
|
|
10
|
+
<item index="2" class="java.lang.String" itemvalue="sentence-transformers" />
|
|
11
|
+
<item index="3" class="java.lang.String" itemvalue="Levenshtein" />
|
|
12
|
+
<item index="4" class="java.lang.String" itemvalue="numpy" />
|
|
13
|
+
<item index="5" class="java.lang.String" itemvalue="roman_numbers" />
|
|
14
|
+
<item index="6" class="java.lang.String" itemvalue="scikit_learn" />
|
|
15
|
+
<item index="7" class="java.lang.String" itemvalue="opencv_python_headless" />
|
|
16
|
+
<item index="8" class="java.lang.String" itemvalue="flask_session" />
|
|
17
|
+
<item index="9" class="java.lang.String" itemvalue="Flask_Login" />
|
|
18
|
+
<item index="10" class="java.lang.String" itemvalue="elasticsearch_dsl" />
|
|
19
|
+
<item index="11" class="java.lang.String" itemvalue="python_dateutil" />
|
|
20
|
+
<item index="12" class="java.lang.String" itemvalue="onnxruntime_gpu" />
|
|
21
|
+
<item index="13" class="java.lang.String" itemvalue="readability_lxml" />
|
|
22
|
+
<item index="14" class="java.lang.String" itemvalue="Flask_Cors" />
|
|
23
|
+
<item index="15" class="java.lang.String" itemvalue="webdriver_manager" />
|
|
24
|
+
<item index="16" class="java.lang.String" itemvalue="elastic_transport" />
|
|
25
|
+
<item index="17" class="java.lang.String" itemvalue="huggingface_hub" />
|
|
26
|
+
<item index="18" class="java.lang.String" itemvalue="python_pptx" />
|
|
27
|
+
<item index="19" class="java.lang.String" itemvalue="opencv_python" />
|
|
28
|
+
</list>
|
|
29
|
+
</value>
|
|
30
|
+
</option>
|
|
31
|
+
</inspection_tool>
|
|
32
|
+
</profile>
|
|
33
|
+
</component>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="Black">
|
|
4
|
+
<option name="sdkName" value="Python 3.9 (Doc Editor)" />
|
|
5
|
+
</component>
|
|
6
|
+
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (plasmapdf)" project-jdk-type="Python SDK" />
|
|
7
|
+
</project>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="ProjectModuleManager">
|
|
4
|
+
<modules>
|
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/plasmapdf.iml" filepath="$PROJECT_DIR$/.idea/plasmapdf.iml" />
|
|
6
|
+
</modules>
|
|
7
|
+
</component>
|
|
8
|
+
</project>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<module type="PYTHON_MODULE" version="4">
|
|
3
|
+
<component name="NewModuleRootManager">
|
|
4
|
+
<content url="file://$MODULE_DIR$">
|
|
5
|
+
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
|
6
|
+
</content>
|
|
7
|
+
<orderEntry type="jdk" jdkName="Python 3.12 (plasmapdf)" jdkType="Python SDK" />
|
|
8
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
9
|
+
</component>
|
|
10
|
+
</module>
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project version="4">
|
|
3
|
+
<component name="AutoImportSettings">
|
|
4
|
+
<option name="autoReloadType" value="SELECTIVE" />
|
|
5
|
+
</component>
|
|
6
|
+
<component name="ChangeListManager">
|
|
7
|
+
<list default="true" id="06be5bdf-8452-4e73-a9ec-fc117070a74d" name="Changes" comment="">
|
|
8
|
+
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
|
|
9
|
+
<change beforePath="$PROJECT_DIR$/pyproject.toml" beforeDir="false" afterPath="$PROJECT_DIR$/pyproject.toml" afterDir="false" />
|
|
10
|
+
</list>
|
|
11
|
+
<option name="SHOW_DIALOG" value="false" />
|
|
12
|
+
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
|
13
|
+
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
|
14
|
+
<option name="LAST_RESOLUTION" value="IGNORE" />
|
|
15
|
+
</component>
|
|
16
|
+
<component name="FileTemplateManagerImpl">
|
|
17
|
+
<option name="RECENT_TEMPLATES">
|
|
18
|
+
<list>
|
|
19
|
+
<option value="Python Script" />
|
|
20
|
+
</list>
|
|
21
|
+
</option>
|
|
22
|
+
</component>
|
|
23
|
+
<component name="Git.Settings">
|
|
24
|
+
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
|
25
|
+
</component>
|
|
26
|
+
<component name="ProjectColorInfo">{
|
|
27
|
+
"associatedIndex": 2
|
|
28
|
+
}</component>
|
|
29
|
+
<component name="ProjectId" id="2kq4XAUrNDXUWjsEPU5s4RQL7Ol" />
|
|
30
|
+
<component name="ProjectViewState">
|
|
31
|
+
<option name="hideEmptyMiddlePackages" value="true" />
|
|
32
|
+
<option name="showLibraryContents" value="true" />
|
|
33
|
+
</component>
|
|
34
|
+
<component name="PropertiesComponent"><![CDATA[{
|
|
35
|
+
"keyToString": {
|
|
36
|
+
"RunOnceActivity.ShowReadmeOnStart": "true",
|
|
37
|
+
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
|
38
|
+
"git-widget-placeholder": "main",
|
|
39
|
+
"ignore.virus.scanning.warn.message": "true",
|
|
40
|
+
"last_opened_file_path": "C:/Users/scrud/source/plasmapdf",
|
|
41
|
+
"node.js.detected.package.eslint": "true",
|
|
42
|
+
"node.js.detected.package.tslint": "true",
|
|
43
|
+
"node.js.selected.package.eslint": "(autodetect)",
|
|
44
|
+
"node.js.selected.package.tslint": "(autodetect)",
|
|
45
|
+
"nodejs_package_manager_path": "npm",
|
|
46
|
+
"vue.rearranger.settings.migration": "true"
|
|
47
|
+
}
|
|
48
|
+
}]]></component>
|
|
49
|
+
<component name="RecentsManager">
|
|
50
|
+
<key name="MoveFile.RECENT_KEYS">
|
|
51
|
+
<recent name="C:\Users\scrud\source\plasmapdf" />
|
|
52
|
+
<recent name="C:\Users\scrud\source\plasmapdf\src\plasmapdf\utils" />
|
|
53
|
+
<recent name="C:\Users\scrud\source\plasmapdf\src\plasmapdf\models" />
|
|
54
|
+
</key>
|
|
55
|
+
</component>
|
|
56
|
+
<component name="SharedIndexes">
|
|
57
|
+
<attachedChunks>
|
|
58
|
+
<set>
|
|
59
|
+
<option value="bundled-js-predefined-1d06a55b98c1-91d5c284f522-JavaScript-PY-241.15989.155" />
|
|
60
|
+
<option value="bundled-python-sdk-babbdf50b680-7c6932dee5e4-com.jetbrains.pycharm.pro.sharedIndexes.bundled-PY-241.15989.155" />
|
|
61
|
+
</set>
|
|
62
|
+
</attachedChunks>
|
|
63
|
+
</component>
|
|
64
|
+
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
|
65
|
+
<component name="TaskManager">
|
|
66
|
+
<task active="true" id="Default" summary="Default task">
|
|
67
|
+
<changelist id="06be5bdf-8452-4e73-a9ec-fc117070a74d" name="Changes" comment="" />
|
|
68
|
+
<created>1723997810798</created>
|
|
69
|
+
<option name="number" value="Default" />
|
|
70
|
+
<option name="presentableId" value="Default" />
|
|
71
|
+
<updated>1723997810798</updated>
|
|
72
|
+
<workItem from="1723997811909" duration="1210000" />
|
|
73
|
+
<workItem from="1724017608867" duration="7485000" />
|
|
74
|
+
<workItem from="1724042530356" duration="2609000" />
|
|
75
|
+
</task>
|
|
76
|
+
<servers />
|
|
77
|
+
</component>
|
|
78
|
+
<component name="TypeScriptGeneratedFilesManager">
|
|
79
|
+
<option name="version" value="3" />
|
|
80
|
+
</component>
|
|
81
|
+
</project>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-present JSv4 <scrudato@umich.edu>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
plasmapdf-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: plasmapdf
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Project-URL: Documentation, https://github.com/JSv4/plasmapdf#readme
|
|
5
|
+
Project-URL: Issues, https://github.com/JSv4/plasmapdf/issues
|
|
6
|
+
Project-URL: Source, https://github.com/JSv4/plasmapdf
|
|
7
|
+
Author-email: JSv4 <scrudato@umich.edu>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE.txt
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Programming Language :: Python
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
18
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
19
|
+
Requires-Python: >=3.8
|
|
20
|
+
Requires-Dist: numpy
|
|
21
|
+
Requires-Dist: pandas
|
|
22
|
+
Requires-Dist: pydantic
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# PlasmaPDF Quick Start Guide
|
|
26
|
+
|
|
27
|
+
PlasmaPDF is a Python library for working with PDF documents, particularly focused on handling annotations and data
|
|
28
|
+
extraction. This guide will walk you through the basic usage of the library.
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
To install PlasmaPDF, use pip:
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
pip install plasmapdf
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Basic Usage
|
|
39
|
+
|
|
40
|
+
### 1. Importing the Library
|
|
41
|
+
|
|
42
|
+
Start by importing the necessary components:
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from plasmapdf.models.PdfDataLayer import makePdfTranslationLayerFromPawlsTokens
|
|
46
|
+
from plasmapdf.models.types import TextSpan, SpanAnnotation, PawlsPagePythonType
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 2. Creating a PdfDataLayer
|
|
50
|
+
|
|
51
|
+
The core of plasmaPDF is the `PdfDataLayer` class. You create an instance of this class using
|
|
52
|
+
the `makePdfTranslationLayerFromPawlsTokens` function:
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
pawls_tokens: list[PawlsPagePythonType] = [
|
|
56
|
+
{
|
|
57
|
+
"page": {"width": 612, "height": 792, "index": 0},
|
|
58
|
+
"tokens": [
|
|
59
|
+
{"x": 72, "y": 72, "width": 50, "height": 12, "text": "Hello"},
|
|
60
|
+
{"x": 130, "y": 72, "width": 50, "height": 12, "text": "World"}
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
pdf_data_layer = makePdfTranslationLayerFromPawlsTokens(pawls_tokens)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 3. Working with Text Spans
|
|
69
|
+
|
|
70
|
+
You can extract raw text from a span in the document:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
span = TextSpan(id="1", start=0, end=11, text="Hello World")
|
|
74
|
+
raw_text = pdf_data_layer.get_raw_text_from_span(span)
|
|
75
|
+
print(raw_text) # Output: "Hello World"
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 4. Creating Annotations
|
|
79
|
+
|
|
80
|
+
To create an annotation:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
span_annotation = SpanAnnotation(span=span, annotation_label="GREETING")
|
|
84
|
+
oc_annotation = pdf_data_layer.create_opencontract_annotation_from_span(span_annotation)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 5. Accessing Document Information
|
|
88
|
+
|
|
89
|
+
You can access various pieces of information about the document:
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
print(pdf_data_layer.doc_text) # Full document text
|
|
93
|
+
print(pdf_data_layer.human_friendly_full_text) # Human-readable version of the text
|
|
94
|
+
print(pdf_data_layer.page_dataframe) # DataFrame with page information
|
|
95
|
+
print(pdf_data_layer.tokens_dataframe) # DataFrame with token information
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Advanced Usage
|
|
99
|
+
|
|
100
|
+
### Working with Multi-Page Documents
|
|
101
|
+
|
|
102
|
+
PlasmaPDF can handle multi-page documents. When you create the `PdfDataLayer`, make sure to include tokens for all
|
|
103
|
+
pages:
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
multi_page_pawls_tokens = [
|
|
107
|
+
{
|
|
108
|
+
"page": {"width": 612, "height": 792, "index": 0},
|
|
109
|
+
"tokens": [...]
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"page": {"width": 612, "height": 792, "index": 1},
|
|
113
|
+
"tokens": [...]
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
|
|
117
|
+
pdf_data_layer = makePdfTranslationLayerFromPawlsTokens(multi_page_pawls_tokens)
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Splitting Spans Across Pages
|
|
121
|
+
|
|
122
|
+
If you have a span that potentially crosses page boundaries, you can split it:
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
long_span = TextSpan(id="2", start=0, end=1000, text="...")
|
|
126
|
+
page_aware_spans = pdf_data_layer.split_span_on_pages(long_span)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Creating OpenContracts Annotations
|
|
130
|
+
|
|
131
|
+
To create an annotation in the OpenContracts format:
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
span = TextSpan(id="3", start=0, end=20, text="Important clause here")
|
|
135
|
+
span_annotation = SpanAnnotation(span=span, annotation_label="IMPORTANT_CLAUSE")
|
|
136
|
+
oc_annotation = pdf_data_layer.create_opencontract_annotation_from_span(span_annotation)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Utility Functions
|
|
140
|
+
|
|
141
|
+
PlasmaPDF includes utility functions for working with job results:
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
from plasmapdf.utils.utils import package_job_results_to_oc_generated_corpus_type
|
|
145
|
+
|
|
146
|
+
# Assume you have job_results, possible_span_labels, possible_doc_labels,
|
|
147
|
+
# possible_relationship_labels, and suggested_label_set
|
|
148
|
+
|
|
149
|
+
corpus = package_job_results_to_oc_generated_corpus_type(
|
|
150
|
+
job_results,
|
|
151
|
+
possible_span_labels,
|
|
152
|
+
possible_doc_labels,
|
|
153
|
+
possible_relationship_labels,
|
|
154
|
+
suggested_label_set
|
|
155
|
+
)
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
This function packages job results into the OpenContracts corpus format.
|
|
159
|
+
|
|
160
|
+
## Testing
|
|
161
|
+
|
|
162
|
+
PlasmaPDF comes with a suite of unit tests. You can run these tests to ensure everything is working correctly:
|
|
163
|
+
|
|
164
|
+
```
|
|
165
|
+
hatch test
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
This will run all the tests in the `tests` directory.
|
|
169
|
+
|
|
170
|
+
## Conclusion
|
|
171
|
+
|
|
172
|
+
This quick start guide covers the basics of using PlasmaPDF. For more detailed information, refer to the full
|
|
173
|
+
documentation or explore the source code. If you encounter any issues or have questions, please refer to the project's
|
|
174
|
+
issue tracker or documentation.
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# PlasmaPDF Quick Start Guide
|
|
2
|
+
|
|
3
|
+
PlasmaPDF is a Python library for working with PDF documents, particularly focused on handling annotations and data
|
|
4
|
+
extraction. This guide will walk you through the basic usage of the library.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
To install PlasmaPDF, use pip:
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
pip install plasmapdf
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Basic Usage
|
|
15
|
+
|
|
16
|
+
### 1. Importing the Library
|
|
17
|
+
|
|
18
|
+
Start by importing the necessary components:
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
from plasmapdf.models.PdfDataLayer import makePdfTranslationLayerFromPawlsTokens
|
|
22
|
+
from plasmapdf.models.types import TextSpan, SpanAnnotation, PawlsPagePythonType
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### 2. Creating a PdfDataLayer
|
|
26
|
+
|
|
27
|
+
The core of plasmaPDF is the `PdfDataLayer` class. You create an instance of this class using
|
|
28
|
+
the `makePdfTranslationLayerFromPawlsTokens` function:
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
pawls_tokens: list[PawlsPagePythonType] = [
|
|
32
|
+
{
|
|
33
|
+
"page": {"width": 612, "height": 792, "index": 0},
|
|
34
|
+
"tokens": [
|
|
35
|
+
{"x": 72, "y": 72, "width": 50, "height": 12, "text": "Hello"},
|
|
36
|
+
{"x": 130, "y": 72, "width": 50, "height": 12, "text": "World"}
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
pdf_data_layer = makePdfTranslationLayerFromPawlsTokens(pawls_tokens)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 3. Working with Text Spans
|
|
45
|
+
|
|
46
|
+
You can extract raw text from a span in the document:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
span = TextSpan(id="1", start=0, end=11, text="Hello World")
|
|
50
|
+
raw_text = pdf_data_layer.get_raw_text_from_span(span)
|
|
51
|
+
print(raw_text) # Output: "Hello World"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 4. Creating Annotations
|
|
55
|
+
|
|
56
|
+
To create an annotation:
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
span_annotation = SpanAnnotation(span=span, annotation_label="GREETING")
|
|
60
|
+
oc_annotation = pdf_data_layer.create_opencontract_annotation_from_span(span_annotation)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 5. Accessing Document Information
|
|
64
|
+
|
|
65
|
+
You can access various pieces of information about the document:
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
print(pdf_data_layer.doc_text) # Full document text
|
|
69
|
+
print(pdf_data_layer.human_friendly_full_text) # Human-readable version of the text
|
|
70
|
+
print(pdf_data_layer.page_dataframe) # DataFrame with page information
|
|
71
|
+
print(pdf_data_layer.tokens_dataframe) # DataFrame with token information
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Advanced Usage
|
|
75
|
+
|
|
76
|
+
### Working with Multi-Page Documents
|
|
77
|
+
|
|
78
|
+
PlasmaPDF can handle multi-page documents. When you create the `PdfDataLayer`, make sure to include tokens for all
|
|
79
|
+
pages:
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
multi_page_pawls_tokens = [
|
|
83
|
+
{
|
|
84
|
+
"page": {"width": 612, "height": 792, "index": 0},
|
|
85
|
+
"tokens": [...]
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"page": {"width": 612, "height": 792, "index": 1},
|
|
89
|
+
"tokens": [...]
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
pdf_data_layer = makePdfTranslationLayerFromPawlsTokens(multi_page_pawls_tokens)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Splitting Spans Across Pages
|
|
97
|
+
|
|
98
|
+
If you have a span that potentially crosses page boundaries, you can split it:
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
long_span = TextSpan(id="2", start=0, end=1000, text="...")
|
|
102
|
+
page_aware_spans = pdf_data_layer.split_span_on_pages(long_span)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Creating OpenContracts Annotations
|
|
106
|
+
|
|
107
|
+
To create an annotation in the OpenContracts format:
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
span = TextSpan(id="3", start=0, end=20, text="Important clause here")
|
|
111
|
+
span_annotation = SpanAnnotation(span=span, annotation_label="IMPORTANT_CLAUSE")
|
|
112
|
+
oc_annotation = pdf_data_layer.create_opencontract_annotation_from_span(span_annotation)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Utility Functions
|
|
116
|
+
|
|
117
|
+
PlasmaPDF includes utility functions for working with job results:
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
from plasmapdf.utils.utils import package_job_results_to_oc_generated_corpus_type
|
|
121
|
+
|
|
122
|
+
# Assume you have job_results, possible_span_labels, possible_doc_labels,
|
|
123
|
+
# possible_relationship_labels, and suggested_label_set
|
|
124
|
+
|
|
125
|
+
corpus = package_job_results_to_oc_generated_corpus_type(
|
|
126
|
+
job_results,
|
|
127
|
+
possible_span_labels,
|
|
128
|
+
possible_doc_labels,
|
|
129
|
+
possible_relationship_labels,
|
|
130
|
+
suggested_label_set
|
|
131
|
+
)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
This function packages job results into the OpenContracts corpus format.
|
|
135
|
+
|
|
136
|
+
## Testing
|
|
137
|
+
|
|
138
|
+
PlasmaPDF comes with a suite of unit tests. You can run these tests to ensure everything is working correctly:
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
hatch test
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
This will run all the tests in the `tests` directory.
|
|
145
|
+
|
|
146
|
+
## Conclusion
|
|
147
|
+
|
|
148
|
+
This quick start guide covers the basics of using PlasmaPDF. For more detailed information, refer to the full
|
|
149
|
+
documentation or explore the source code. If you encounter any issues or have questions, please refer to the project's
|
|
150
|
+
issue tracker or documentation.
|