{"id":8287,"date":"2023-02-10T00:13:20","date_gmt":"2023-02-09T23:13:20","guid":{"rendered":"https:\/\/smartdatamodels.org\/?page_id=8287"},"modified":"2023-10-02T01:02:11","modified_gmt":"2023-10-01T23:02:11","slug":"pysmatdatamodels-documentation","status":"publish","type":"page","link":"https:\/\/smartdatamodels.org\/index.php\/pysmatdatamodels-documentation\/","title":{"rendered":"pysmartdatamodels documentation"},"content":{"rendered":"<p><strong>1- Load all datamodels in a dict like the official list. Function load_all_datamodels()<\/strong><br \/>\nReturns a dict with all data models with this object structure<br \/>\n    &#8211; repoName: The name of the subject<br \/>\n    &#8211; repoLink: the link to the repository of the subject<br \/>\n    &#8211; dataModels: An array with all the datamodels of this subject<br \/>\n    &#8211; domains: an array to the domains that this subject belongs to<br \/>\n    Parameters:<br \/>\n      None<\/p>\n<p>    Returns:<br \/>\n       array of objects with the description of the subject<\/p>\n<p><strong>2- Load all attributes in a dict like the official export of attributes. Function load_all_attributes()<\/strong><br \/>\nReturns an array of objects describing every attribute in the data models<br \/>\n    &#8211; _id: identifier of the item<br \/>\n    &#8211; property: the name of the attribute<br \/>\n    &#8211; dataModel: the data model this attribute is present<br \/>\n    &#8211; repoName: the subject this data model belongs to<br \/>\n    &#8211; description: the description of the attribute<br \/>\n    &#8211; typeNGSI: Whether it is a property, Geoproperty, or relationship<br \/>\n    &#8211; modelTags: inherited from the data model tags<br \/>\n    &#8211; license: link to the license for the data model<br \/>\n    &#8211; schemaVersion: version of the data model<br \/>\n    &#8211; type: data type<br \/>\n    &#8211; model: when available the reference model for the attribute<br \/>\n    &#8211; units: when available the recommended units for the attribute<br \/>\n    &#8211; format: either date, or time, or date-time, or URI, etc the format of the attribute<br \/>\n    Parameters:<\/p>\n<p>    Returns:<br \/>\n       array of objects with the description of the subject<\/p>\n<p><strong>3- List all data models. Function list_all_datamodels()<\/strong><br \/>\nList the names of the entities defined in the data models.<br \/>\n    Parameters:<\/p>\n<p>    Returns:<br \/>\n    array of strings: data models&#8217; names<\/p>\n<p><strong>4- List all subjects. Function list_all_subjects()<\/strong><br \/>\nList the names of the subjects (groups of data models). The subject&#8217;s names define repositories with the name dataModel.subject at the root of the https:\/\/github.com\/smart-data-models site<br \/>\n      Parameters:<\/p>\n<p>  Returns:<br \/>\n    array of strings: subjects&#8217; names<\/p>\n<p><strong>5- List the data models of a subject. Function datamodels_subject(subject)<\/strong><br \/>\nList the names of the entities defined in the data models.<br \/>\n    Parameters:<br \/>\n      subject: name of the subject<\/p>\n<p>    Returns:<br \/>\n     if subject is found<br \/>\n       array of strings: data models&#8217; names belonging to the subject<br \/>\n     if subject is not found<br \/>\n       False<\/p>\n<p><strong>6- List description of an attribute. Function description_attribute(subject, datamodel, attribute)<\/strong><br \/>\nList the description of an attribute belonging to a subject and data model.<br \/>\n    Parameters:<br \/>\n      subject: name of the subject<br \/>\n      datamodel: name of the data model<br \/>\n      attribute: name of the attribute<\/p>\n<p>    Returns:<br \/>\n      if subject, datamodel and attribute are found<br \/>\n        string: attribute&#8217;s description<br \/>\n      if any of the input parameters is not found<br \/>\n        False<\/p>\n<p><strong>7- List data-type of an attribute. Function datatype_attribute(subject, datamodel, attribute)<\/strong><br \/>\nList the data type of an attribute belonging to a subject and data model.<br \/>\n    Parameters:<br \/>\n    subject: name of the subject<br \/>\n    datamodel: name of the data model<br \/>\n    attribute: name of the attribute<\/p>\n<p>    Returns:<br \/>\n      if subject, datamodel and attribute are found<br \/>\n        string: attribute&#8217;s data type<br \/>\n      if any of the input parameters is not found<br \/>\n        False<\/p>\n<p><strong>8- Give reference model for an attribute. Function model_attribute(subject, datamodel, attribute)<\/strong><br \/>\nList the model of an attribute (when available) belonging to a subject and data model.<br \/>\n      Parameters:<br \/>\n        subject: name of the subject<br \/>\n        datamodel: name of the data model<br \/>\n        attribute: name of the attribute<\/p>\n<p>      Returns:<br \/>\n        if subject, datamodel and attribute are found<br \/>\n          string: attribute model&#8217;s URL<br \/>\n        if any of the input parameters is not found or there is not a model<br \/>\n          False<\/p>\n<p><strong>9- Give reference units for an attribute. Function attributes_datamodel(subject, datamodel)<\/strong><br \/>\nList the recommended units of an attribute belonging to a subject and data model.<br \/>\n      Parameters:<br \/>\n        subject: name of the subject<br \/>\n        datamodel: name of the data model<br \/>\n        attribute: name of the attribute<\/p>\n<p>    Returns:<br \/>\n      if subject, datamodel and attribute are found<br \/>\n        string: acronym\/text of the recommended units<br \/>\n      if any of the input parameters is not found or there are not recommended units<br \/>\n        False<\/p>\n<p><strong>10- List the attributes of a data model. Function attributes_datamodel(subject, datamodel)<\/strong><br \/>\nList the attributes of a data model (currently only first level ones) .<br \/>\n      Parameters:<br \/>\n      subject: name of the subject<br \/>\n      datamodel: name of the data model<\/p>\n<p>      Returns:<br \/>\n        if subject and datamodel  are found<br \/>\n          array: attribute&#8217;s names<br \/>\n        if any of the input parameters is not found<br \/>\n          False<\/p>\n<p><strong>11- List the NGSI type (Property, Relationship or Geoproperty) of the attribute. Function ngsi_datatype_attribute(subject, datamodel, attribute)<\/strong><br \/>\nList the NGSI data type of an attribute (Property, Relationship or Geoproperty) belonging to a subject and data model.<br \/>\n      Parameters:<br \/>\n        subject: name of the subject<br \/>\n        datamodel: name of the data model<br \/>\n        attribute: name of the attribute<\/p>\n<p>      Returns:<br \/>\n        if subject, datamodel and attribute are found<br \/>\n          string: NGSI data type<br \/>\n        if any of the input parameters is not found<br \/>\n          False<\/p>\n<p><strong>12- Print a list of data models attributes separated by a separator. Function print_datamodel(subject, datamodel, separator, meta_attributes)<\/strong><br \/>\nValidates a json schema defining a data model.<br \/>\n    Parameters:<br \/>\n      schema_url: url of the schema (public available). (i.e. raw version of a github repo https:\/\/raw.githubusercontent.com\/smart-data-models\/dataModel.Aeronautics\/master\/AircraftModel\/schema.json<\/p>\n<p>    Returns:<br \/>\n      object with four elements:<br \/>\n    &#8211; documentationStatusofProperties: For each first level attribute lists if the attribute is documented and includes the description (when available). Also the NGSI type if is set and which one is described.<br \/>\n    Example:<br \/>\n        &#8220;dateCreated&#8221;:<br \/>\n              {<br \/>\n              &#8220;x-ngsi&#8221;: true,<br \/>\n              &#8220;x-ngsi_text&#8221;: &#8220;ok to Property&#8221;,<br \/>\n              &#8220;documented&#8221;: true,<br \/>\n              &#8220;text&#8221;: &#8220;This will usually be allocated by the storage platform.. Entity creation timestamp&#8221;<br \/>\n              },<br \/>\n    &#8211; schemaDiagnose: It counts the attributes with right descriptions and those which don&#8217;t.<br \/>\n    &#8211; alreadyUsedProperties: It identifies attributes that have already been used in other data models and includes their definition<br \/>\n    &#8211; availableProperties: Identifies those attributes which are not already included in any other data model<\/p>\n<p><strong>13- Returns the link to the repository of a subject. Function subject_repolink(subject)<\/strong><br \/>\nPrint the different elements of the attributes of a data model separated by a given separator.<br \/>\n    Parameters:<br \/>\n      subject: name of the subject<br \/>\n      datamodel: name of the data model<br \/>\n      separator: string between the different elements printed<br \/>\n      meta_attributes: list of different qualifiers of an attribute<br \/>\n         property: the name of the attribute<br \/>\n         type: the data type of the attribute (json schema basic types)<br \/>\n         dataModel: the data model the attribute belongs to<br \/>\n         repoName: the subject the attribute belongs to<br \/>\n         description: the definition of the attribute<br \/>\n         typeNGSI: the NGSI type, Property, Relationship or Geoproperty<br \/>\n         modelTags: the tags assigned to the data model<br \/>\n         format: For those attributes having it the format, i.e. date-time<br \/>\n         units: For those attributes having it the recommended units, i.e. meters<br \/>\n         model: For those attributes having it the reference model, i.e. https:\/\/schema.org\/Number<\/p>\n<p>    Returns:<br \/>\n      It prints a version of the attributes separated by the separator listing the meta_attributes specified<br \/>\n      A variable with the same strings<br \/>\n      if any of the input parameters is not found it returns false<\/p>\n<p><strong>14- Returns the links to the repositories of a data model name. Function datamodel_repolink(datamodel)<\/strong><br \/>\nIt returns the direct link to the repository of the subject if it is found and False if not .<br \/>\n    Parameters:<br \/>\n      subject: name of the subject<\/p>\n<p>    Returns:<br \/>\n     if subject is found<br \/>\n       url of the github repository. Example for subject User it returns &#8216;https:\/\/github.com\/smart-data-models\/dataModel.User.git&#8217;<br \/>\n     if subject is not found<br \/>\n       False<\/p>\n<p><strong>15- Update the official data model list or the database of attributes from the source. Function update_data()<\/strong><br \/>\nIt returns an array with the direct links to the repositories where is located the data model if it is found and False if not found.<br \/>\n    Parameters:<br \/>\n      datamodel: name of the data model<\/p>\n<p>    Returns:<br \/>\n     if data model is found<br \/>\n       array of urls (even with one single result) to the github repository. Example for subject Activity it returns [&#8216;https:\/\/github.com\/smart-data-models\/dataModel.User.git&#8217;]\n     if data model is not found<br \/>\n       False<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1- Load all datamodels in a dict like the official list. Function load_all_datamodels() Returns a dict with all data models with this object structure &#8211; repoName: The name of the subject &#8211; repoLink: the link to the repository of the subject &#8211; dataModels: An array with all the datamodels of&#8230; <a class=\"continue-reading-link\" href=\"https:\/\/smartdatamodels.org\/index.php\/pysmatdatamodels-documentation\/\">More&#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"class_list":["post-8287","page","type-page","status-publish","hentry"],"jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":6408,"url":"https:\/\/smartdatamodels.org\/index.php\/export-of-database-of-attributes-of-the-smart-data-models\/","url_meta":{"origin":8287,"position":0},"title":"Export of database of attributes of the Smart Data Models","author":"maestro","date":"21\/07\/2022","format":false,"excerpt":"For some developers is interesting to access the database of attributes you can search in the main menu -> Search You have it in this link https:\/\/smartdatamodels.org\/extra\/smartdatamodels.json the file (It is a large one). It has a CC-BY license so feel free to use it and we will be happy\u2026","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":8295,"url":"https:\/\/smartdatamodels.org\/index.php\/pysmartdatamodels-code-example\/","url_meta":{"origin":8287,"position":1},"title":"pysmartdatamodels code example","author":"maestro","date":"10\/02\/2023","format":false,"excerpt":"from pysmartdatamodels import pysmartdatamodels as sdm subject = \"dataModel.Weather\" dataModel = \"WeatherForecast\" attribute = \"precipitation\" print(sdm.load_all_datamodels()) print(len(sdm.load_all_attributes())) # there is more than 19.000 to get all listed print(sdm.list_all_datamodels()) print(sdm.list_all_subjects()) print(sdm.datamodels_subject(\"dataModel.Weather\")) print(sdm.description_attribute(subject, dataModel, attribute)) print(sdm.datatype_attribute(subject, dataModel, attribute)) print(sdm.model_attribute(subject, dataModel, attribute)) print(sdm.units_attribute(subject, dataModel, attribute)) print(sdm.attributes_datamodel(subject, dataModel)) print(sdm.subject_repolink(subject)) print(sdm.datamodel_repolink(dataModel)) print(sdm.print_datamodel(subject, dataModel, \",\", [\u2026","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1329,"url":"https:\/\/smartdatamodels.org\/index.php\/draft-a-data-model\/","url_meta":{"origin":8287,"position":2},"title":"Draft a data model","author":"maestro","date":"24\/01\/2021","format":false,"excerpt":"Steps to create your new data model in json schema Supposedly you know how many fields you want your data model to have and what data types they would be. 1.- Copy this text 2.- Open in a new window this web. 3.- Paste the text in the left form\u2026","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/smartdatamodels.org\/wp-content\/uploads\/2021\/06\/validation.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/smartdatamodels.org\/wp-content\/uploads\/2021\/06\/validation.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/smartdatamodels.org\/wp-content\/uploads\/2021\/06\/validation.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1476,"url":"https:\/\/smartdatamodels.org\/index.php\/instructions-to-be-listed-as-a-data-model-adopter-of-smart-data-models\/","url_meta":{"origin":8287,"position":3},"title":"Instructions to be listed as a data model adopter of Smart Data Models","author":"maestro","date":"01\/02\/2021","format":false,"excerpt":"find here the Instructions to be listed as a data model adopter. Try to do a Pull Request on the repository\/ies of the data model you are a user\/adopter of (recommended). See this example https:\/\/github.com\/smart-data-models\/dataModel.Battery\/blob\/master\/BatteryStatus\/ADOPTERS.yaml . If this option does not suit you, here there is an alternative Create a\u2026","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1221,"url":"https:\/\/smartdatamodels.org\/index.php\/procedure-for-adding-new-data-model\/","url_meta":{"origin":8287,"position":4},"title":"Procedure for adding new data model","author":"maestro","date":"02\/01\/2021","format":false,"excerpt":"Supposedly the data model meets the contribution manual requirements these steps should be taken If there is to create new subject warn these points: Rename 'main' branch to 'master' Check that the page for the repo is published. It could take to github up to 5 minutes since you enable\u2026","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":16,"url":"https:\/\/smartdatamodels.org\/index.php\/about\/","url_meta":{"origin":8287,"position":5},"title":"About","author":"maestro","date":"17\/03\/2020","format":false,"excerpt":"Smart Data Models Program Board Welcome to Smart Data Models Program. This is a collaborative initiative impulsed by FIWARE Foundation, TMForum,\u00a0IUDX, and OASC many other people and organizations (see statistics) contributing to the data models. Purpose These data models are open-licensed allowing free use, free modification, and free sharing of\u2026","rel":"","context":"Similar post","block_context":{"text":"Similar post","link":""},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/smartdatamodels.org\/wp-content\/uploads\/2020\/12\/220px-TM_Forum_Logo.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/smartdatamodels.org\/index.php\/wp-json\/wp\/v2\/pages\/8287","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smartdatamodels.org\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/smartdatamodels.org\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/smartdatamodels.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smartdatamodels.org\/index.php\/wp-json\/wp\/v2\/comments?post=8287"}],"version-history":[{"count":8,"href":"https:\/\/smartdatamodels.org\/index.php\/wp-json\/wp\/v2\/pages\/8287\/revisions"}],"predecessor-version":[{"id":9755,"href":"https:\/\/smartdatamodels.org\/index.php\/wp-json\/wp\/v2\/pages\/8287\/revisions\/9755"}],"wp:attachment":[{"href":"https:\/\/smartdatamodels.org\/index.php\/wp-json\/wp\/v2\/media?parent=8287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}