{ "info": { "author": "Kyle Hundman", "author_email": "khundman@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "# Marve\nA measurement relation extractor\n\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\nMarve leverages [grobid-quantities](https://github.com/kermitt2/grobid-quantities) and [Stanford CoreNLP](http://stanfordnlp.github.io/CoreNLP) to extract and normalize measurements and their related entities and descriptors from natural language text. \n\n```shell\n\t\n\tsample = \"The patient returned to Europe at 28 weeks of gestation.\"\n\n\t#Simplified output\n\t#-----------------\n\tvalue: \"28\"\n\tunit: \"weeks\"\n\tquantified: \"gestation\"\n\trelated: [\"patient\", \"Europe\"]\n```\n\nMarve employs grobid-quantities to find measurement values, units, and a limited set of \"quantified\" substances using linear CRF models trained on a labeled corpus of text. CoreNLP is then used to link measurements to related words in the sentence using word dependencies and POS tags from CoreNLP. Common dependency/POS patterns relating measurements to other words/entities are specified in `/marve/dependency_patterns.json` and can be adjusted without modifying code. \n\n## Installation\n\nRunning Marve requires grobid-quantities and CoreNLP to be running:\n\nDownload and unzip [CoreNLP](http://stanfordnlp.github.io/CoreNLP/download.html):\n```shell\ncurl -LOk \"http://nlp.stanford.edu/software/stanford-corenlp-full-2016-10-31.zip\" | unzip /stanford-corenlp-full-2016-10-31.zip\n```\n\nRun (requires Java 8):\n```shell\ncd /stanford-corenlp-full-2016-10-31 | java -mx4g -cp \"*\" edu.stanford.nlp.pipeline.StanfordCoreNLPServer 9000\n```\n\nInstall grobid by following instructions [here](http://grobid.readthedocs.io/en/latest/Install-Grobid/)

\nThen follow [grobid-quantities instructions](https://github.com/kermitt2/grobid-quantities) to install, build, train, and run\n\nInstall Marve:
\n`pip install marve`\n\n## Usage\nOnce both CoreNLP and grobid-quantities are running, Marve can be used as such:\n\n```shell\n# coding: utf-8\n\nfrom marve import Measurements as m\n\n# Strings longer than a paragraph should be split before passing to Marve\n_test = \"The patient returned to Europe at 28 weeks of gestation.\"\n\ncoreNLP = \"http://localhost:9000\"\ngrobid = \"http://localhost:8080\"\npatterns = \"dependency_patterns.json\"\nwrite_to = \"sample_output.txt\"\n\nm.extract(_test, coreNLP, grobid, patterns, write_to, show_graph=False, pretty=True, simplify=False)\n````\n\n(This example can be found in `sample.py`)\n\nIMPORTANT: Text should be in sentence or paragraph chunks before passing to Marve.\n\n Note : The first time Marve is run, a timeout error might be thrown due to longer CoreNLP model loading times. If this happens, run again and CorenLP should run properly.\n\n## Dependency and Part-of-Speech Patterns\nMarve will only return words related to measurements if they meet criteria laid out in the dependency pattern file `/marve/dependency_patterns.json`.\n\nTake the phrase `\"a spatial resolution of 10m\"`. Marve uses a graph to represent each sentence, where edges are the dependencies between words (represented in green ovals below) and nodes are words and their part-of-speech (POS) labels (represented in blue). \n\n![example](https://github.jpl.nasa.gov/hundman/marve/blob/master/blob/example.png)\n\nThere are a handful of general patterns that relate measurement units, values, and other related words or entities in a sentence. For instance, units are generally connected to values via the numerical modifier (`\"nummod\"`) dependency (see above). Nominal modifiers (`\"nmod\"`) is then a common dependency linking units to the thing being quantified. Common patterns linking values, units, and related words have been defined in `/marve/dependency_patterns.json`, and the bit of JSON that would match `\"m\"` to `\"resolution\"` in our above example is:\n\n\n```shell\n\"nmod\": {\n \"enhanced\": true,\n \"of\":{\n \"measurement_types\": [\"space_between\", \"attached\"],\n \"pos_in\":{\n \"NN\": null\n }\n }\n}\n```\n\nHere's how this example matches:

\n1. `nmod` is the dependency type between `m` and `resolution`

\n2. Since we utilized CoreNLP's enhanced dependency parser, we also see `:of` attached on the end of `nmod`. Since enhanced is set to `true`, the `of` must be attached to the dependency

\n3. Because the measurement is `10m` we identify it as being an `attached` `measurement_type`

\n4. `\"pos_in\"` forces the part of speech of the attached node to contain at least one of its keys. In this case, \"NN\" means the part of speech must be a noun (valid POS tags could be: `NN`, `NNS`, `NNP`, `NNPS`). Since `NN`'s value is null, we are finished and can return resolution as a related word and add it to the output. For some POS tags such as `VB`, we might need to continue traversing edges in the graph, in which case the value could specify a function to be called (e.g. `get_cousin()`)
\n\nAll such dependency patterns listed in the JSON will be evaluated and if there are any matching patters, they will be added as related words for a measurement.\n\n## API\n\n```shell\nextract(content, corenlp, grobid, dependency_patterns_file, output_file=None, show_graph=False, pretty=False, simplify=False)\n\nReturns extracted measurements from a sentence or paragraph.\n\nParameters: \tcontent: string\n\t\t\t\t\t\tSentence or paragraph to extract measurements from.\n\n\t\t\t\tcorenlp: string\n\t\t\t\t\t\tCoreNLP server endpoint (e.g. \"http://localhost:9200\"). \n\n\t\t\t\tgrobid: string\n\t\t\t\t\t\tGrobid server endpoint (e.g. \"http://localhost:8080\").\n\n\t\t\t\tdependency_patterns_file: string\n\t\t\t\t\t\tFilepath to JSON file containing valid dependency/POS patterns for \n\t\t\t\t\t\textracting words and entities related to measurements.\n\n\t\t\t\toutput_file: string, optional\n\t\t\t\t\t\tFile to write extracted measurement output to.\n\n\t\t\t\tshow_graph: boolean, optional\n\t\t\t\t\t\tIf True, a visualization of the dependency and POS network graph \n\t\t\t\t\t\twill be displayed for each sentence parsed.\n\n\t\t\t\tpretty: boolean, optional\n\t\t\t\t\t\tIf True, JSON written to file will be indented. If False, one extraction \n\t\t\t\t\t\tdoc per line will be written to the output file\n\n\t\t\t\tsimplify: boolean, optional \n\t\t\t\t\t\tIf True, only the measurement, unit, and related words of the extracted \n\t\t\t\t\t\toutput will be returned and written to the output file (see 'Output Options' \n\t\t\t\t\t\tsection for more detail).\n\nReturns:\t\tdict: see \"Output Options\" below\n```\n\n## Output Options\n\n#### simple=True\n\n```shell\n{\"value\": 6, \"unit\": \"year\", \"quantified\": {}, \"related\": {\"period\": [\"study\"]}}\n```\n\n#### simple=False, pretty=False\n\n```shell\n{\n\t\"type\": \"value\",\n\t\"quantity\": {\n\t\t\"parsedValue\": 6,\n\t\t\"rawValue\": \"six\",\n\t\t\"rawUnit\": {\n\t\t\t\"offsetStart\": 13,\n\t\t\t\"offsetEnd\": 14,\n\t\t\t\"tokenIndices\": [\n\t\t\t\t\"3\"\n\t\t\t],\n\t\t\t\"after\": \" \",\n\t\t\t\"name\": \"year\"\n\t\t},\n\t\t\"offsetEnd\": 131,\n\t\t\"offsetStart\": 128,\n\t\t\"tokenIndex\": 24,\n\t\t\"type\": \"time\"\n\t},\n\t\"related\": [\n\t\t{\n\t\t\t\"rawName\": \"period\",\n\t\t\t\"connector\": \"\",\n\t\t\t\"offsetEnd\": 21,\n\t\t\t\"relationForm\": \"compound\",\n\t\t\t\"offsetStart\": 15,\n\t\t\t\"tokenIndex\": 5,\n\t\t\t\"descriptors\": [\n\t\t\t\t{\n\t\t\t\t\t\"rawName\": \"year\",\n\t\t\t\t\t\"tokenIndex\": \"4\"\n\t\t\t\t}\n\t\t\t]\n\t\t}\n\t]\n}\n```\n\n## License\nMarve is distributed under [Apache 2.0 license](http://www.apache.org/licenses/LICENSE-2.0).\n\nContact: Kyle Hundman ()\n\n## Acknowledgements\n\n* [Chris Mattmann](http://sunset.usc.edu/~mattmann/), JPL\n* Sonny Koliwad, JPL\n* Jason Hyon, JPL\n* [Ian Colwell](https://github.com/iancolwell), JPL", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/khundman/marve", "keywords": null, "license": "Apache License\n Version 2.0, January 2004\n http://www.apache.org/licenses/\n\n TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n 1. Definitions.\n\n \"License\" shall mean the terms and conditions for use, reproduction,\n and distribution as defined by Sections 1 through 9 of this document.\n\n \"Licensor\" shall mean the copyright owner or entity authorized by\n the copyright owner that is granting the License.\n\n \"Legal Entity\" shall mean the union of the acting entity and all\n other entities that control, are controlled by, or are under common\n control with that entity. For the purposes of this definition,\n \"control\" means (i) the power, direct or indirect, to cause the\n direction or management of such entity, whether by contract or\n otherwise, or (ii) ownership of fifty percent (50%) or more of the\n outstanding shares, or (iii) beneficial ownership of such entity.\n\n \"You\" (or \"Your\") shall mean an individual or Legal Entity\n exercising permissions granted by this License.\n\n \"Source\" form shall mean the preferred form for making modifications,\n including but not limited to software source code, documentation\n source, and configuration files.\n\n \"Object\" form shall mean any form resulting from mechanical\n transformation or translation of a Source form, including but\n not limited to compiled object code, generated documentation,\n and conversions to other media types.\n\n \"Work\" shall mean the work of authorship, whether in Source or\n Object form, made available under the License, as indicated by a\n copyright notice that is included in or attached to the work\n (an example is provided in the Appendix below).\n\n \"Derivative Works\" shall mean any work, whether in Source or Object\n form, that is based on (or derived from) the Work and for which the\n editorial revisions, annotations, elaborations, or other modifications\n represent, as a whole, an original work of authorship. For the purposes\n of this License, Derivative Works shall not include works that remain\n separable from, or merely link (or bind by name) to the interfaces of,\n the Work and Derivative Works thereof.\n\n \"Contribution\" shall mean any work of authorship, including\n the original version of the Work and any modifications or additions\n to that Work or Derivative Works thereof, that is intentionally\n submitted to Licensor for inclusion in the Work by the copyright owner\n or by an individual or Legal Entity authorized to submit on behalf of\n the copyright owner. For the purposes of this definition, \"submitted\"\n means any form of electronic, verbal, or written communication sent\n to the Licensor or its representatives, including but not limited to\n communication on electronic mailing lists, source code control systems,\n and issue tracking systems that are managed by, or on behalf of, the\n Licensor for the purpose of discussing and improving the Work, but\n excluding communication that is conspicuously marked or otherwise\n designated in writing by the copyright owner as \"Not a Contribution.\"\n\n \"Contributor\" shall mean Licensor and any individual or Legal Entity\n on behalf of whom a Contribution has been received by Licensor and\n subsequently incorporated within the Work.\n\n 2. Grant of Copyright License. Subject to the terms and conditions of\n this License, each Contributor hereby grants to You a perpetual,\n worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n copyright license to reproduce, prepare Derivative Works of,\n publicly display, publicly perform, sublicense, and distribute the\n Work and such Derivative Works in Source or Object form.\n\n 3. Grant of Patent License. Subject to the terms and conditions of\n this License, each Contributor hereby grants to You a perpetual,\n worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n (except as stated in this section) patent license to make, have made,\n use, offer to sell, sell, import, and otherwise transfer the Work,\n where such license applies only to those patent claims licensable\n by such Contributor that are necessarily infringed by their\n Contribution(s) alone or by combination of their Contribution(s)\n with the Work to which such Contribution(s) was submitted. If You\n institute patent litigation against any entity (including a\n cross-claim or counterclaim in a lawsuit) alleging that the Work\n or a Contribution incorporated within the Work constitutes direct\n or contributory patent infringement, then any patent licenses\n granted to You under this License for that Work shall terminate\n as of the date such litigation is filed.\n\n 4. Redistribution. You may reproduce and distribute copies of the\n Work or Derivative Works thereof in any medium, with or without\n modifications, and in Source or Object form, provided that You\n meet the following conditions:\n\n (a) You must give any other recipients of the Work or\n Derivative Works a copy of this License; and\n\n (b) You must cause any modified files to carry prominent notices\n stating that You changed the files; and\n\n (c) You must retain, in the Source form of any Derivative Works\n that You distribute, all copyright, patent, trademark, and\n attribution notices from the Source form of the Work,\n excluding those notices that do not pertain to any part of\n the Derivative Works; and\n\n (d) If the Work includes a \"NOTICE\" text file as part of its\n distribution, then any Derivative Works that You distribute must\n include a readable copy of the attribution notices contained\n within such NOTICE file, excluding those notices that do not\n pertain to any part of the Derivative Works, in at least one\n of the following places: within a NOTICE text file distributed\n as part of the Derivative Works; within the Source form or\n documentation, if provided along with the Derivative Works; or,\n within a display generated by the Derivative Works, if and\n wherever such third-party notices normally appear. The contents\n of the NOTICE file are for informational purposes only and\n do not modify the License. You may add Your own attribution\n notices within Derivative Works that You distribute, alongside\n or as an addendum to the NOTICE text from the Work, provided\n that such additional attribution notices cannot be construed\n as modifying the License.\n\n You may add Your own copyright statement to Your modifications and\n may provide additional or different license terms and conditions\n for use, reproduction, or distribution of Your modifications, or\n for any such Derivative Works as a whole, provided Your use,\n reproduction, and distribution of the Work otherwise complies with\n the conditions stated in this License.\n\n 5. Submission of Contributions. Unless You explicitly state otherwise,\n any Contribution intentionally submitted for inclusion in the Work\n by You to the Licensor shall be under the terms and conditions of\n this License, without any additional terms or conditions.\n Notwithstanding the above, nothing herein shall supersede or modify\n the terms of any separate license agreement you may have executed\n with Licensor regarding such Contributions.\n\n 6. Trademarks. This License does not grant permission to use the trade\n names, trademarks, service marks, or product names of the Licensor,\n except as required for reasonable and customary use in describing the\n origin of the Work and reproducing the content of the NOTICE file.\n\n 7. Disclaimer of Warranty. Unless required by applicable law or\n agreed to in writing, Licensor provides the Work (and each\n Contributor provides its Contributions) on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n implied, including, without limitation, any warranties or conditions\n of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n PARTICULAR PURPOSE. You are solely responsible for determining the\n appropriateness of using or redistributing the Work and assume any\n risks associated with Your exercise of permissions under this License.\n\n 8. Limitation of Liability. In no event and under no legal theory,\n whether in tort (including negligence), contract, or otherwise,\n unless required by applicable law (such as deliberate and grossly\n negligent acts) or agreed to in writing, shall any Contributor be\n liable to You for damages, including any direct, indirect, special,\n incidental, or consequential damages of any character arising as a\n result of this License or out of the use or inability to use the\n Work (including but not limited to damages for loss of goodwill,\n work stoppage, computer failure or malfunction, or any and all\n other commercial damages or losses), even if such Contributor\n has been advised of the possibility of such damages.\n\n 9. Accepting Warranty or Additional Liability. While redistributing\n the Work or Derivative Works thereof, You may choose to offer,\n and charge a fee for, acceptance of support, warranty, indemnity,\n or other liability obligations and/or rights consistent with this\n License. However, in accepting such obligations, You may act only\n on Your own behalf and on Your sole responsibility, not on behalf\n of any other Contributor, and only if You agree to indemnify,\n defend, and hold each Contributor harmless for any liability\n incurred by, or claims asserted against, such Contributor by reason\n of your accepting any such warranty or additional liability.\n\n END OF TERMS AND CONDITIONS\n\n APPENDIX: How to apply the Apache License to your work.\n\n To apply the Apache License to your work, attach the following\n boilerplate notice, with the fields enclosed by brackets \"{}\"\n replaced with your own identifying information. (Don't include\n the brackets!) The text should be enclosed in the appropriate\n comment syntax for the file format. We also recommend that a\n file or class name and description of purpose be included on the\n same \"printed page\" as the copyright notice for easier\n identification within third-party archives.\n\n Copyright {yyyy} {name of copyright owner}\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.", "maintainer": null, "maintainer_email": null, "name": "marve", "package_url": "https://pypi.org/project/marve/", "platform": "any", "project_url": "https://pypi.org/project/marve/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/khundman/marve" }, "release_url": "https://pypi.org/project/marve/0.0.7/", "requires_dist": null, "requires_python": null, "summary": "Package for extracting measurements and related entities from text.", "version": "0.0.7" }, "last_serial": 2583588, "releases": { "0.0.6": [ { "comment_text": "", "digests": { "md5": "db181f7baf8df4182d18e6d6d55fb09a", "sha256": "29b29a3c111f9133b442e1706329a62bb888013f0be3f812460cb112ca6c556f" }, "downloads": -1, "filename": "marve-0.0.6.tar.gz", "has_sig": false, "md5_digest": "db181f7baf8df4182d18e6d6d55fb09a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21521, "upload_time": "2017-01-04T17:08:39", "url": "https://files.pythonhosted.org/packages/b1/7b/c8352cdf8b796ea7d4148ce70dc39fe1579f0790d10fe6065a9e651dbca9/marve-0.0.6.tar.gz" } ], "0.0.7": [ { "comment_text": "", "digests": { "md5": "8a2a322e6732706777032d66def6cd5b", "sha256": "880fca840878bdb91a08a29871da4010bac1cdda1fd4f26f6e583628083af4e2" }, "downloads": -1, "filename": "marve-0.0.7.tar.gz", "has_sig": false, "md5_digest": "8a2a322e6732706777032d66def6cd5b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21278, "upload_time": "2017-01-18T22:30:48", "url": "https://files.pythonhosted.org/packages/f9/70/2b8d7095f5df8bbed1f52e46638d6b0123d66bcd3c4bffd7f0d99a94325a/marve-0.0.7.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8a2a322e6732706777032d66def6cd5b", "sha256": "880fca840878bdb91a08a29871da4010bac1cdda1fd4f26f6e583628083af4e2" }, "downloads": -1, "filename": "marve-0.0.7.tar.gz", "has_sig": false, "md5_digest": "8a2a322e6732706777032d66def6cd5b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21278, "upload_time": "2017-01-18T22:30:48", "url": "https://files.pythonhosted.org/packages/f9/70/2b8d7095f5df8bbed1f52e46638d6b0123d66bcd3c4bffd7f0d99a94325a/marve-0.0.7.tar.gz" } ] }