Solved

P&ID contextualization, with indexed content

  • 27 September 2023
  • 4 replies
  • 73 views

Userlevel 1
Badge

Hi 

I received a few P&ID diagram where the tags aren’t spelled out in-place (because the space perhaps was limiting), but just an indexed number is given. And in a separate table, the index is mapped with the tag name.

Please see that attached image which can provide further illustration.

 

I am not sure if the OCR + contextualization logic can map the index out and place the tag at the correct place. I am thinking it is unlikely. In such case, can you please provide clues on how one can map it - some amount of manual steps and tweaks, if expected, are fine.

 

Thanks for your inputs! 

icon

Best answer by Ola Liabøtrø 28 September 2023, 09:19

View original

4 replies

Userlevel 1

Hi! Is the table in a separate file, or in the same file? 

At least if it is in the same file, one could consider to just detect the tags in the table. 
Just being able to navigate by clicking the numbers would be a plus, but especially since the tags seem to be very similar, I would think that a navigating user would be just as happy to see the table (with some extra information) as seeing the drawing in this case. E.g. how do they decide if they want to check out 54 rather than 55 here? 

That said, an attempt to do it could proceed as follows: 

  • Run regular diagram detect to detect known tags
  • For each detected tag named ABC123 with id X, produce the sample “00 [ABC123]”, also add a sample “00”. 
  • Run diagram detect in beta with pattern_mode=True, min_tokens=1 and entities=[{“sample”:sample, “id”: X}]
  • The detections will now have names  like “60 T-00XX”, but also “60”, “51” etc. 
  • Finally, for each detection of a single two-digit number “XX” with a corresponding pattern detection “XX <TAG>” and regular detection of “<TAG>”, take the box of XX and insert the data corresponding to the tag and make annotations accordingly. 
Userlevel 1
Badge

Ola,

Thank you for your answers, I’ll be curious to try these steps myself. For the start how do I run the “diagram detect” program with the specified pattern modes. I am sure there is an API, a ready reference/guide will be very helpful indeed.

Regards

Alex

 

Userlevel 1

There is the cognite sdk documentation: https://cognite-sdk-python.readthedocs-hosted.com/en/latest/contextualization.html#engineering-diagrams

And the API docs: https://api-docs.cognite.com/20230101-beta/tag/Engineering-diagrams/operation/diagramDetect/ 

But it could be more thorough on how to use pattern_mode. 
You need to use api_subversion=”beta” when creating your client_config, e.g. 

creds = OAuthInteractive(
client_id=client_id,
scopes=[f"https://{cluster}.cognitedata.com/.default"],
authority_url=authority_uri
)

client_config = ClientConfig(
client_name="my-special-client",
base_url=f"https://{cluster}.cognitedata.com",
project=project,
credentials=creds,
api_subversion="beta",
)

client = CogniteClient(client_config)

You would do something like
 

entities = [{"name": "CBP-BIQ-SBBQ-01", "id": 123}, ...]
file_external_id = "something"


detect_job = client.diagrams.detect(
file_references=[
FileReference(file_external_id=file_external_id, first_page=1, last_page=1),
],
entities=entities,
pattern_mode=False
)


detect_job_result = detect_job.result

sample_entities = [
{"sample": f"00 {entity["name"]}", "id": entity["id"]}
for entity in result["items"][0]["annotations"]
for entity in a["entities"] # Usually only one per annotation, if names are unique
] + [{"sample": "00", "id": 1}]

pattern_detect_job = client.diagrams.detect(
file_references=[
FileReference(file_external_id=file_external_id, first_page=1, last_page=1),
],
entities=sample_entities,
min_tokens=1,
pattern_mode=True
)

pattern_detect_result = pattern_detect_job.result





 

Userlevel 1
Badge

Awesome, let me give it a try next week!

Reply