Skip to content

Commit

Permalink
Results (#20)
Browse files Browse the repository at this point in the history
* result test

* ta2 schemas, docs, results changes

* UUID removal

* fix

* more tries

* better

* final

* really

* build fix

---------

Co-authored-by: Justin Gawrilow <[email protected]>
  • Loading branch information
jgawrilo and Justin Gawrilow authored Apr 9, 2024
1 parent 3c4646b commit 612dac2
Show file tree
Hide file tree
Showing 8 changed files with 831 additions and 165 deletions.
643 changes: 489 additions & 154 deletions README.md

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions cdr_schemas/area_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@


class AreaType(str, Enum):
Map_Area = "map_area"
Legend_Area = "legend_area"
CrossSection = "cross_section"
OCR = "ocr"
Polygon_Legend_Area = "polygon_legend_area"
Line_Point_Legend_Area = "line_point_legend_area"
Line_Legend_Area = "line_legend_area"
Point_Legend_Area = "point_legend_area"
Correlation_Diagram = "correlation_diagram"
Map_Area = "Map_Area"
Legend_Area = "Legend_Area"
CrossSection = "CrossSection"
OCR = "OCR"
Polygon_Legend_Area = "Polygon_Legend_Area"
Line_Point_Legend_Area = "Line_Point_Legend_Area"
Line_Legend_Area = "Line_Legend_Area"
Point_Legend_Area = "Point_Legend_Area"
Correlation_Diagram = "Correlation_Diagram"


class Area_Extraction(BaseModel):
Expand Down
80 changes: 80 additions & 0 deletions cdr_schemas/document.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
from typing import Optional

from pydantic import BaseModel, Field


class DocumentProvenance(BaseModel):
"""JSON model for Document Provenance"""

external_system_name: str = Field(
..., description="Name of system storing document"
)
external_system_id: str = Field(None, description="The system ID of the document")
external_system_url: str = Field(
None, description="Name of system storing document"
)


class Document(BaseModel):
"""JSON model for user-facing document metadata"""

id: str = Field(..., description="The internal ID of the document")
title: str = Field(..., description="Title of the document")
is_open: bool = Field(
...,
description="Whether document is open or not.",
)

pages: Optional[int] = Field(None, description="Document page count")

provenance: Optional[list[DocumentProvenance]] = Field(
None, description="provenance list"
)

system: str = Field(
...,
description="""
The name of the system used.
""",
)
system_version: str = Field(
...,
description="""
The version of the system used.
""",
)


class DocumentExtraction(BaseModel):
"""JSON model for user-facing document metadata"""

id: str | None = Field(None, description="The internal ID of the xtraction")
document_id: str = Field(None, description="The internal ID of the source document")
extraction_type: str = Field(
..., description="The type of model that produced the extraction"
)
extraction_label: str = Field(
..., description="The classification of the extraction within its model"
)
score: float | None = Field(None, description="The confidence of the extraction")
bbox: tuple[float, float, float, float] | None = Field(
None, description="The bounding box of the extraction"
)
page_num: int | None = Field(None, description="The page number of the extraction")
external_link: str | None = Field(None, description="A link to the extraction")
data: dict | None = Field(
None, description="Extra information about the extraction"
)

system: str = Field(
...,
description="""
The name of the system used.
""",
)
system_version: str = Field(
...,
description="""
The version of the system used.
""",
)
14 changes: 12 additions & 2 deletions cdr_schemas/feature_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,18 @@ class FeatureResults(BaseModel):
A list of legend extractions with associated polygon feature results.
""",
)
cog_area_extractions: Optional[List[Area_Extraction]]
cog_metadata_extractions: Optional[List[CogMetaData]]
cog_area_extractions: Optional[List[Area_Extraction]] = Field(
...,
description="""
Higher level extraction pulled off a cog - legend area, map area, ocr text area, etc.
""",
)
cog_metadata_extractions: Optional[List[CogMetaData]] = Field(
...,
description="""
Metadata extractions pulled off a cog.
""",
)
system: str = Field(
...,
description="""
Expand Down
37 changes: 37 additions & 0 deletions cdr_schemas/map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from typing import Optional

from pydantic import BaseModel, Field


class MapProvenance(BaseModel):
"""JSON model for Document Provenance"""

system_name: str = Field(..., description="Name of system storing map")
id: str = Field(None, description="The system ID of the map")
url: str = Field(None, description="URL of map at system storing map")


class Map(BaseModel):
"""JSON model for 'Map''"""

id: str = Field(..., description="The CDR ID of the Map")
provenance: Optional[list[MapProvenance]] = Field(
None, description="provenance list"
)
is_open: bool = Field(
...,
description="Whether map is open or not.",
)

system: str = Field(
...,
description="""
The name of the system used.
""",
)
system_version: str = Field(
...,
description="""
The version of the system used.
""",
)
32 changes: 32 additions & 0 deletions cdr_schemas/map_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from typing import List, Optional

from pydantic import BaseModel, Field

from cdr_schemas.feature_results import FeatureResults
from cdr_schemas.georeference import GeoreferenceResults


class MapResults(BaseModel):
"""
All results for map.
"""

cog_id: str = Field(
...,
description="""
Cog id.
""",
)

georef_results: Optional[List[GeoreferenceResults]] = Field(
...,
description="""
A list of georef results from systems.
""",
)
extraction_results: Optional[List[FeatureResults]] = Field(
...,
description="""
A list of feature extraction results from systems.
""",
)
162 changes: 162 additions & 0 deletions cdr_schemas/mineral.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
from datetime import datetime
from enum import Enum
from typing import List, Optional

from pydantic import BaseModel, Field

from cdr_schemas.document import Document


class Geometry(Enum):
Point = "Point"
Polygon = "Polygon"


class ResourceReserveCategory(Enum):
INFERRED = "Inferred Mineral Resource"
INDICATED = "Indicated Mineral Resource"
MEASURED = "Measured Mineral Resource"
PROBABLE = "Probable Mineral Reserve"
PROVEN = "Proven Mineral Reserve"


class GeologyInfo(BaseModel):
age: Optional[str] = Field(description="Age of the geologic unit or event")
unit_name: Optional[str] = Field(description="Name of the geologic unit")
description: Optional[str]
lithology: Optional[list[str]]
process: Optional[list[str]]
environment: Optional[list[str]]
comments: Optional[str]


class Ore(BaseModel):
ore_unit: str = Field(
description="The unit in which ore quantity is measured, eg, metric tonnes"
)
ore_value: float = Field(description="The value of ore quantity")


class DepositType(BaseModel):
name: str = Field(description="Deposit type name")
environment: str = Field(description="Deposit type environment")
group: str = Field(description="Deposit type group")


class DepositTypeCandidate(BaseModel):
observed_name: str = Field(
description="Source dataset that the site info is retrieved from. e.g., MRDS"
)
normalized_uri: DepositType = Field(
description="The deposit type of an inventory item"
)
confidence: float = Field(description="Score deposit type of an inventory item")
source: str = Field(
description="Source of the classification (automated model version / SME / etc...)"
)


class BoundingBox(BaseModel):
x_min: float
x_max: float
y_min: float
y_max: float


class PageInfo(BaseModel):
page: int
bounding_box: Optional[BoundingBox] = Field(
description="Coordinates of the document where reference is found"
)


class Reference(BaseModel):
document: Document
page_info: List[PageInfo] = Field(
description="List of pages and their respective bounding boxes where the reference is found"
)


class EvidenceLayer(BaseModel):
name: str
relevance_score: float


class MappableCriteria(BaseModel):
criteria: str
theoretical: Optional[str]
potential_dataset: Optional[list[EvidenceLayer]]
supporting_references: list[Reference]


class MineralSystem(BaseModel):
deposit_type: list[DepositType]
source: list[MappableCriteria]
pathway: list[MappableCriteria]
trap: Optional[list[MappableCriteria]]
preservation: Optional[list[MappableCriteria]]
energy: Optional[list[MappableCriteria]]
outflow: Optional[list[MappableCriteria]]


class Commodity(BaseModel):
name: str


class Grade(BaseModel):
grade_unit: str = Field(
description="The unit in which grade is measured, eg, percent"
)
grade_value: float = Field(description="The value of grade")


class MineralInventory(BaseModel):
commodity: Commodity = Field(description="The commodity of an inventory item")
observed_commodity: Optional[str] = Field(
description="The observed commodity in the source data (textual format)"
)
category: Optional[ResourceReserveCategory] = Field(
description="The category of an inventory item"
)
ore: Optional[Ore] = Field(description="The ore of an inventory item")
grade: Optional[Grade] = Field(description="The grade of an inventory item")
cutoff_grade: Optional[Grade] = Field(
description="The cutoff grade of the observed inventory item"
)
contained_metal: Optional[float] = Field(
description="The quantity of a contained metal in an inventory item"
)
reference: Reference = Field(description="The reference of an inventory item")
date: Optional[datetime] = Field(
description="When in the point of time mineral inventory valid"
)
zone: Optional[str] = Field(
description="zone of mineral site where inventory item was discovered"
)


class LocationInfo(BaseModel):
location: Geometry = Field(
description="Type: Polygon or Point, value indicates the geolocation of the site"
)
crs: str = Field(
description="The Coordinate Reference System (CRS) of the location"
)
country: Optional[str] = Field(description="Country that the mine site resides in")
state_or_province: Optional[str] = Field(
description="State or province that the mine site resides in"
)


class MineralSite(BaseModel):
source_id: str = Field(
description="Source dataset that the site info is retrieved from. e.g., MRDS"
)
record_id: str = Field(
description="Unique ID of the record that the info is retrieved from e.g., 10022920"
)
name: Optional[str] = Field(description="Name of the mine, e.g., Tungsten Jim")
mineral_inventory: list[MineralInventory]
location_info: LocationInfo
geology_info: Optional[GeologyInfo]
deposit_type_candidate: list[DepositTypeCandidate]
10 changes: 10 additions & 0 deletions dev/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
from jinja2 import Template
from pydantic_mermaid import MermaidGenerator

import cdr_schemas.area_extraction
import cdr_schemas.document
import cdr_schemas.events
import cdr_schemas.feature_results
import cdr_schemas.features.line_features
import cdr_schemas.features.point_features
import cdr_schemas.features.polygon_features
import cdr_schemas.georeference
import cdr_schemas.map
import cdr_schemas.map_results
import cdr_schemas.metadata
import cdr_schemas.mineral


@dataclass
Expand Down Expand Up @@ -47,13 +52,18 @@ def run():
template = Template(Path("docs/schemas.md.j2").read_text())

modules = [
Module(title="area extraction", ref=cdr_schemas.area_extraction),
Module(title="georeference", ref=cdr_schemas.georeference),
Module(title="metadata", ref=cdr_schemas.metadata),
Module(title="feature results", ref=cdr_schemas.feature_results),
Module(title="point feature", ref=cdr_schemas.features.point_features),
Module(title="line feature", ref=cdr_schemas.features.line_features),
Module(title="polygon feature", ref=cdr_schemas.features.polygon_features),
Module(title="cog metadata", ref=cdr_schemas.metadata),
Module(title="document", ref=cdr_schemas.document),
Module(title="mineral", ref=cdr_schemas.mineral),
Module(title="map results", ref=cdr_schemas.map_results),
Module(title="map", ref=cdr_schemas.map),
]

for m in modules:
Expand Down

0 comments on commit 612dac2

Please sign in to comment.