{
"info": {
"author": "Homme Zwaagstra",
"author_email": "hrz@geodata.soton.ac.uk",
"bugtrack_url": null,
"classifiers": [],
"description": "# Python SKOS\n\n[](http://travis-ci.org/geo-data/python-skos)\n\n## Overview\n\nThis package provides a basic implementation of *some* of the core\nelements of the SKOS object model, as well as an API for loading SKOS\nXML resources. See the\n[SKOS Primer](http://www.w3.org/TR/skos-primer) for an introduction to\nSKOS.\n\nThe object model builds on [SQLAlchemy](http://sqlalchemy.org) to\nprovide persistence and querying of the object model from within a SQL\ndatabase.\n\n## Usage\n\nFirstly, the package supports Python's\n[logging module](http://docs.python.org/library/logging.html) which\ncan provide useful feedback about various module actions so let's\nactivate it:\n\n >>> import logging\n >>> logging.basicConfig(level=logging.INFO)\n \nThe package reads graphs generated by the `rdflib` library so let's\nparse a (rather contrived) SKOS XML file into a graph:\n\n >>> import rdflib\n >>> xml = \"\"\"\n \n \n Acoustic backscatter in the water column\n Includes all parameters covering the strength of acoustic signal return, including absolute measurements of returning signal strength as well as parameters expressed as backscatter (the proportion of transmitted signal returned)\n \n \n \n \n \n \n Test Collection\n A collection of concepts used as a test\n \n \n \n Another test concept\n Just another concept\n \n \n \n \n \"\"\"\n >>> graph = rdflib.Graph()\n >>> graph.parse(data=xml, format=\"application/rdf+xml\")\n\nNow we can can use the `skos.RDFLoader` object to access the SKOS data\nas Python objects:\n\n >>> import skos\n >>> loader = skos.RDFLoader(graph)\n \nThis implements a mapping interface:\n\n >>> loader.keys()\n ['http://my.fake.domain/test1',\n 'http://my.fake.domain/test2',\n 'http://my.fake.domain/collection']\n >>> loader.values()\n [,\n ,\n ]\n >>> len(loader)\n 3\n >>> concept = loader['http://my.fake.domain/test1']\n >>> concept\n \n \nAs well as some convenience methods returning mappings of specific\ntypes:\n\n >>> loader.getConcepts()\n {'http://my.fake.domain/test1': ,\n 'http://my.fake.domain/test2': }\n >>> loader.getCollections()\n {'http://my.fake.domain/collection': }\n >>> loader.getConceptSchemes() # we haven't got any `ConceptScheme`s\n {} \n\nNote that you can convert your Python SKOS objects back into their RDF\nrepresentation using the `RDFBuilder` class:\n\n >>> builder = RDFBuilder()\n >>> objects = loader.values()\n >>> another_graph = builder.build(objects)\n\nThe `RDFLoader` constructor also takes a `max_depth` parameter which\ndefaults to `0`. This parameter determines the depth to which RDF\nresources are resolved i.e. it is used to limit the depth to which\nlinks are recursively followed. E.g. the following will allow one\nlevel of external resources to be parsed and resolved:\n\n >>> loader = skos.RDFLoader(graph, max_depth=1) # you need to be online for this!\n INFO:skos:parsing http://vocab.nerc.ac.uk/collection/L19/current/005/\n INFO:skos:parsing http://vocab.nerc.ac.uk/collection/P05/current/014/\n INFO:skos:parsing http://vocab.nerc.ac.uk/collection/P01/current/ACBSADCP/\n\nIf you want to resolve an entire (and potentially very large!) graph\nthen use `max_depth=float('inf')`.\n\nAnother constructor parameter is the boolean flag `flat`. This can\nalso be toggled post-instantiation using the `RDFLoader.flat`\nproperty. When set to `False` (the default) only SKOS objects present\nin the inital graph are directly referenced by the loader: objects\ncreated indirectly by parsing other resources will only be referenced\nby the top level objects:\n\n >>> loader.keys() # lists 3 objects\n ['http://my.fake.domain/test1',\n 'http://my.fake.domain/test2',\n 'http://my.fake.domain/collection']\n >>> concept = loader['http://my.fake.domain/test1']\n >>> concept.synonyms # other objects are still correctly referenced by the object model\n {'http://vocab.nerc.ac.uk/collection/L19/current/005/': }\n >>> 'http://vocab.nerc.ac.uk/collection/L19/current/005/' in loader # but are not referenced directly\n False\n >>> loader.flat = True # flatten the structure so *all* objects are directly referenced\n >>> loader.keys() # lists all 6 objects\n ['http://vocab.nerc.ac.uk/collection/P05/current/014/',\n 'http://vocab.nerc.ac.uk/collection/L19/current/005/',\n 'http://my.fake.domain/collection',\n 'http://my.fake.domain/test1',\n 'http://my.fake.domain/test2',\n 'http://vocab.nerc.ac.uk/collection/P01/current/ACBSADCP/']\n >>> 'http://vocab.nerc.ac.uk/collection/L19/current/005/' in loader\n True\n\nThe `Concept.synonyms` demonstrated above shows the container (an\ninstance of `skos.Concepts`) into which `skos::exactMatch` and\n`owlxml::sameAs` references are placed. The `skos.Concepts` container\nclass is a mapping that is mutable via the `set`-like `add` and\n`discard` methods, as well responding to `del` on keys:\n\n >>> synonym = skos.Concept('test3', 'a synonym for test1', 'a definition')\n >>> concept.synonyms.add(synonym)\n >>> concept.synonyms\n {'http://vocab.nerc.ac.uk/collection/L19/current/005/': ,\n 'test3': }\n >>> del concept.synonyms['test3'] # or...\n >>> concept.synonyms.discard(synonym)\n\nSimilar to `Concept.synonyms` `Concept.broader`, `Concept.narrower`\nand `Concept.related` are all instances of `skos.Concepts`:\n\n >>> assert concept in concept.broader['http://vocab.nerc.ac.uk/collection/P05/current/014/'].narrower\n\n`Concept` instances also provide easy access to the other SKOS data:\n\n >>> concept.uri\n 'http://my.fake.domain/test1'\n >>> concept.prefLabel\n 'Acoustic backscatter in the water column'\n >>> concept.definition\n 'Includes all parameters covering the strength of acoustic signal return, including absolute measurements of returning signal strength as well as parameters expressed as backscatter (the proportion of transmitted signal returned)'\n\nAccess to the `ConceptScheme` and `Collection` objects to which a\nconcept belongs is also available via the `Concept.schemes` and\n`Concept.collections` properties respectively:\n\n >>> concept.collections\n {'http://my.fake.domain/collection': }\n >>> collection = concept.collections['http://my.fake.domain/collection']\n >>> assert concept in collection.members\n \nAs well as the `Collection.members` property, `Collection` instances\nprovide access to the other SKOS data:\n\n >>> collection.uri\n 'http://my.fake.domain/collection'\n >>> collection.title\n collection.title\n >>> collection.description\n 'A collection of concepts used as a test'\n\n`Collection.members` is a `skos.Concepts` instance, so new members can\nadded and removed using the `skos.Concepts` interface:\n\n >>> collection.members.add(synonym)\n >>> del collection.members['test3']\n\n### Integrating with SQLAlchemy\n\n`python-skos` has been designed to be integrated with the SQLAlchemy\nORM when required. This provides scalable data persistence and\nquerying capabilities. The following example uses an in-memory SQLite\ndatabase to provide a taste of what is possible. Explore the\n[SQLAlchemy ORM documentation](http://docs.sqlalchemy.org/en/latest/)\nto build on this, using alternative databases and querying\ntechniques...\n\n >>> from sqlalchemy import create_engine\n >>> engine = create_engine('sqlite:///:memory:') # the in-memory database\n >>> from sqlalchemy.orm import sessionmaker\n >>> Session = sessionmaker(bind=engine)\n >>> session1 = Session() # get a session handle on the database\n >>> skos.Base.metadata.create_all(session1.connection()) # create the required database schema\n >>> session1.add_all(loader.values()) # add all the skos objects to the database\n >>> session1.commit() # commit these changes\n\n >>> session2 = Session() # a new database session, created somewhere else ;)\n >>> session2.query(skos.Collection).first() # obtain our one and only collection\n \n >>> # get all concepts that have the string 'water' in them:\n >>> session2.query(skos.Concept).filter(skos.Concept.prefLabel.ilike('%water%')).all()\n [,\n ]\n\n## Requirements\n\n- [Python](http://www.python.org) == 2.{6,7}\n- [SQLAlchemy](http://www.sqlalchemy.org) SQLAlchemy >= 0.7.5\n- [RDFLib](http://pypi.python.org/pypi/rdflib) >= 2.4.2\n- [iso8601plus](http://pypi.python.org/pypi/iso8601plus)\n- [unittest2](http://pypi.python.org/pypi/unittest2) if running the tests with Python < 2.7\n\n## Download\n\nCurrent and previous versions of the software are available at\n and\n.\n\n## Installation\n\nDownload and unpack the source, then run the following from the root\ndistribution directory:\n\n python setup.py install\n\nIt is recommended that you also run:\n\n python setup.py test\n\nThis exercises the comprehensive package test suite.\n\n## Limitations\n\n- Only part of the more recent SKOS core object model is\n supported. Extending the code to support more of the SKOS\n specification should not be difficult, however.\n\n## Issues and Contributing\n\nPlease report bugs or issues using the\n[GitHub issue tracker](https://github.com/geo-data/python-skos).\n\nCode and documentation contributions are very welcome, either as GitHub pull\nrequests or patches.\n\n## License\n\nThe [BSD 2-Clause](http://opensource.org/licenses/BSD-2-Clause).\n\n## Contact\n\nHomme Zwaagstra \n",
"description_content_type": null,
"docs_url": null,
"download_url": "UNKNOWN",
"downloads": {
"last_day": -1,
"last_month": -1,
"last_week": -1
},
"home_page": "http://github.com/geo-data/python-skos",
"keywords": null,
"license": "BSD",
"maintainer": null,
"maintainer_email": null,
"name": "python-skos",
"package_url": "https://pypi.org/project/python-skos/",
"platform": "UNKNOWN",
"project_url": "https://pypi.org/project/python-skos/",
"project_urls": {
"Download": "UNKNOWN",
"Homepage": "http://github.com/geo-data/python-skos"
},
"release_url": "https://pypi.org/project/python-skos/0.1.1/",
"requires_dist": null,
"requires_python": null,
"summary": "A basic implementation of some core elements of the SKOS object model",
"version": "0.1.1"
},
"last_serial": 1230369,
"releases": {
"0.0.1": [
{
"comment_text": "",
"digests": {
"md5": "575c67c51a85a474267b8c115131e107",
"sha256": "c5a2a756d266bdfb82b6134900756c40339757ab960b7bc512a26db03df3c981"
},
"downloads": -1,
"filename": "python-skos-0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "575c67c51a85a474267b8c115131e107",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 10290,
"upload_time": "2012-05-08T18:19:38",
"url": "https://files.pythonhosted.org/packages/38/f9/6a80f4220389669a87496fb12b6a1620bb7a0fd1538c7f4af724cf27d21b/python-skos-0.0.1.tar.gz"
}
],
"0.0.2": [
{
"comment_text": "",
"digests": {
"md5": "73a951dd17572fa363ec1c9dd5b1a6a2",
"sha256": "1364996e3f2622d422b18a55a7204aeee39731d636b24f2ead4184a61c0e7e08"
},
"downloads": -1,
"filename": "python-skos-0.0.2.tar.gz",
"has_sig": false,
"md5_digest": "73a951dd17572fa363ec1c9dd5b1a6a2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 10554,
"upload_time": "2012-05-24T11:01:52",
"url": "https://files.pythonhosted.org/packages/71/9e/99802fc7a0623f842b72cad3ce05453acd01b47321f786e6d293a102bcc7/python-skos-0.0.2.tar.gz"
}
],
"0.0.3": [
{
"comment_text": "",
"digests": {
"md5": "629e6116792eac40eac732ba9bc4abf5",
"sha256": "df42699fb00c7f45d2ec215ab601071d41f275f1d187914be174053df95f91a6"
},
"downloads": -1,
"filename": "python-skos-0.0.3.tar.gz",
"has_sig": false,
"md5_digest": "629e6116792eac40eac732ba9bc4abf5",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 11101,
"upload_time": "2012-05-29T15:20:41",
"url": "https://files.pythonhosted.org/packages/9b/15/93ee83b6b9f4254c78a4fdb4c856b1fadc5a225345cb031ba2276bf3e609/python-skos-0.0.3.tar.gz"
}
],
"0.1.1": [
{
"comment_text": "",
"digests": {
"md5": "7a09d6165cacf33ebc4f7be48cf79b94",
"sha256": "85ad03c8210ff394d89ec3af86a9ca6dcf9ba7400447182cce8a12b0e2f8f8d0"
},
"downloads": -1,
"filename": "python-skos-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "7a09d6165cacf33ebc4f7be48cf79b94",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 14751,
"upload_time": "2014-09-19T11:41:48",
"url": "https://files.pythonhosted.org/packages/e5/ed/a944d4557f44995ed085ee20fd8dcef70fb6c2cfe08b16db8cd58edf87f9/python-skos-0.1.1.tar.gz"
}
]
},
"urls": [
{
"comment_text": "",
"digests": {
"md5": "7a09d6165cacf33ebc4f7be48cf79b94",
"sha256": "85ad03c8210ff394d89ec3af86a9ca6dcf9ba7400447182cce8a12b0e2f8f8d0"
},
"downloads": -1,
"filename": "python-skos-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "7a09d6165cacf33ebc4f7be48cf79b94",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 14751,
"upload_time": "2014-09-19T11:41:48",
"url": "https://files.pythonhosted.org/packages/e5/ed/a944d4557f44995ed085ee20fd8dcef70fb6c2cfe08b16db8cd58edf87f9/python-skos-0.1.1.tar.gz"
}
]
}