### Install development requirements Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/introduction/contributing.md Install necessary dependencies for local development. ```bash cd ChemDataExtractor pip install -r requirements/development.txt ``` -------------------------------- ### Install ChemDataExtractor from source Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/getting_started.md Use these commands to install the package manually after downloading or cloning the repository. ```bash $ cd chemdataextractor $ python setup.py install ``` -------------------------------- ### Install PyTest Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/Introduction.md Command to install the PyTest package for running tests. ```bash $ pip install -U pytest ``` -------------------------------- ### Install ChemDataExtractor using Pip Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/Introduction.md Suitable for users who already have Python installed. Requires Microsoft Visual C++ Build Tools on Windows. ```bash $ pip install ChemDataExtractor ``` -------------------------------- ### Install ChemDataExtractor via pip Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/getting_started.md Use this command to install the package from the Python Package Index. ```bash $ pip install chemdataextractor2 ``` -------------------------------- ### XHR Event Listener Setup Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/tests/data/relex/curie_training_set/c3nr33950e.html Sets up event listeners for XHR (XMLHttpRequest) events like 'load', 'error', 'abort', and 'timeout'. This is crucial for monitoring network request lifecycles. ```javascript f.on("new-xhr",function(t){var e=this;e.totalCbs=0,e.called=0,e.cbTime=0,e.end=r,e.ended=!1,e.xhrGuids={},e.lastSize=null,h&&(h>34||h<10)||window.opera||t.addEventListener("progress",function(t){e.lastSize=t.loaded},!1)}) ``` -------------------------------- ### Serialized Record Output Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/introduction/new_property.md Example output showing the nested structure of extracted records. ```default [{'BoilingPoint': {'altitude': {'Altitude': {'compound': {'Compound': {'names': ['MgO']}}, 'raw_units': 'm', 'raw_value': '100', 'specifier': 'altitude', 'units': 'Meter^(1.0)', 'value': [100.0]}}, 'compound': {'Compound': {'names': ['MgO']}}, 'raw_units': 'K', 'raw_value': '900', 'specifier': 'boiling point', 'units': 'Kelvin^(1.0)', 'value': [900.0]}}] ``` -------------------------------- ### Subclassing TemperatureModel for BoilingPoint Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/migration_guides/migration_guide.md Example of transforming an existing model to use the new TemperatureModel. Remove value and units properties as they are included by default. ```python from chemdataextractor.model import TemperatureModel, StringType, ModelType from chemdataextractor.model import Compound class BoilingPoint(TemperatureModel): compound = ModelType(Compound) parsers = [BpParser()] ``` -------------------------------- ### Detect Abbreviation Spans Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/source_code_docs/nlp.md Use detect_spans to get the token ranges (start, end) for detected abbreviations and their long forms. ```python abbr_spans, long_spans = abbr_detector.detect_spans(tokens) ``` -------------------------------- ### Manage Configuration Settings Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/source_code_docs/chemdataextractor.md Demonstrates initializing a configuration object and performing basic key-value operations. Note that multiple instances pointing to the same file may cause data loss due to overwriting. ```default c = Config() c['foo'] = 'bar' print c['foo'] ``` ```default c = Config('~/matt/anotherconfig.yml') c['where'] = 'in a different file' ``` -------------------------------- ### Access Specific Document Element Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/introduction/reading_docs.md Get a specific element from the document's element stream by its index. This example retrieves a Paragraph element. ```python para = doc.elements[14] para ``` -------------------------------- ### Initialize Config Instance Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/examples/using_config_file.ipynb Import the `Config` module and create an instance by providing the path to your YAML configuration file. This sets up the configuration for CDE. ```python from chemdataextractor.config import Config import os example_path = os.path.join('tests', 'data', 'test_config.yml') c = Config(example_path) ``` -------------------------------- ### Directly Tokenize Text with ChemWordTokenizer Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/introduction/nlp.md Instantiate `ChemWordTokenizer` and use its `tokenize` method to get a list of word tokens from a string. The `span_tokenize` method returns start and end character offsets for each token. ```python >>> from chemdataextractor.nlp.tokenize import ChemWordTokenizer >>> cwt = ChemWordTokenizer() >>> cwt.tokenize('1H NMR spectra were recorded on a 300 MHz BRUKER DPX300 spectrometer.') ['1H', 'NMR', 'spectra', 'were', 'recorded', 'on', 'a', '300', 'MHz', 'BRUKER', 'DPX300', 'spectrometer', '.'] ``` ```python >>> cwt.span_tokenize('1H NMR spectra were recorded on a 300 MHz BRUKER DPX300 spectrometer.') [(0, 2), (3, 6), (7, 14), (15, 19), (20, 28), (29, 31), (32, 33), (34, 37), (38, 41), (42, 48), (49, 55), (56, 68), (68, 69)] ``` -------------------------------- ### Element Initialization and Parameters Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/source_code_docs/doc.md Details on how to initialize an element and the parameters it accepts. ```APIDOC ## Element Initialization If intended as part of a [`chemdataextractor.doc.document.Document`](#chemdataextractor.doc.document.Document), an element should either be initialized with a reference to its containing document, or its `document` attribute should be set as soon as possible. If the element is being passed in to a [`chemdataextractor.doc.document.Document`](#chemdataextractor.doc.document.Document) to initialise it, the `document` attribute is automatically set during the initialisation of the document, so the user does not need to worry about this. ### Parameters * **text** (*str*) – The text contained in this element. * **start** (*int*) – (Optional) The starting index of the sentence within the containing element. Default 0. * **end** (*int*) – (Optional) The end index of the sentence within the containing element. Defualt None * **word_tokenizer** ([*WordTokenizer*](nlp.md#chemdataextractor.nlp.tokenize.WordTokenizer)) – (Optional) Word tokenizer for this element. Default [`ChemWordTokenizer`](nlp.md#chemdataextractor.nlp.tokenize.ChemWordTokenizer). * **lexicon** ([*Lexicon*](nlp.md#chemdataextractor.nlp.lexicon.Lexicon)) – (Optional) Lexicon for this element. The lexicon stores all the occurences of unique words and can provide Brown clusters for the words. Default [`ChemLexicon`](nlp.md#chemdataextractor.nlp.lexicon.ChemLexicon) * **abbreviation_detector** ([*AbbreviationDetector*](nlp.md#chemdataextractor.nlp.abbrev.AbbreviationDetector)) – (Optional) The abbreviation detector for this element. Default [`ChemAbbreviationDetector`](nlp.md#chemdataextractor.nlp.abbrev.ChemAbbreviationDetector). * **pos_tagger** ([*BaseTagger*](nlp.md#chemdataextractor.nlp.tag.BaseTagger)) – (Optional) The part of speech tagger for this element. Default [`ChemCrfPosTagger`](nlp.md#chemdataextractor.nlp.pos.ChemCrfPosTagger). * **ner_tagger** ([*BaseTagger*](nlp.md#chemdataextractor.nlp.tag.BaseTagger)) – (Optional) The named entity recognition tagger for this element. Default `CemTagger` * **document** ([*Document*](#chemdataextractor.doc.document.Document)) – (Optional) The document containing this element. * **label** (*str*) – (Optional) The label for the captioned element, e.g. Table 1 would have a label of 1. * **id** ([*Any*](parse.md#chemdataextractor.parse.elements.Any)) – (Optional) Some identifier for this element. Must be equatable. * **models** (*list* *[**chemdataextractor.models.BaseModel* *]*) – (Optional) A list of models for this element to parse. If the element is part of another element (e.g. a [`Sentence`](#chemdataextractor.doc.text.Sentence) inside a [`Paragraph`](#chemdataextractor.doc.text.Paragraph)), or is part of a [`Document`](#chemdataextractor.doc.document.Document), this is set automatically to be the same as that of the containing element, unless manually set otherwise. ``` -------------------------------- ### Initialize Document with Models Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/introduction/finding_records.md Create a document object with specific headings, paragraphs, and extraction models. ```python >>> from chemdataextractor.doc import Document, Heading, Paragraph >>> doc = Document( Heading('5,10,15,20-Tetra(4-carboxyphenyl)porphyrin (3).'), Paragraph('m.p. 90°C.'), Paragraph('Melting points were measured in Tetrahydrofuran (THF).'), models=[Compound, MeltingPoint] ) ``` -------------------------------- ### Clone the repository Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/introduction/contributing.md Initial step to obtain a local copy of the project for development. ```bash git clone https://github.com//ChemDataExtractor.git ``` -------------------------------- ### Build HTML documentation with Sphinx Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/introduction/contributing.md Execute this command from the project's documentation working directory to compile the HTML output. ```bash $ sphinx-build -b html docs docs/_build/html ``` -------------------------------- ### Python Function Docstring Example Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/Introduction.md A comprehensive docstring example for Python functions, including a short description, usage example, notes, parameter details, and potential exceptions. This follows best practices for code documentation. ```python def from_string(self, fstring, fname=None, readers=None): """Create a Document from a byte string containing the contents of a file. Usage:: contents = open('paper.html', 'rb').read() doc = Document.from_string(contents) .. note:: This method expects a byte string, not a unicode string (in contrast to most methods in ChemDataExtractor). :param bytes fstring: A byte string containing the contents of a file. :param string fname: (Optional) The filename. Used to help determine file format. :param list[chemdataextractor.reader.base.BaseReader] readers: (Optional) List of readers to use. :raises: ReaderError: If specified readers are not found """ ``` -------------------------------- ### Install ChemDataExtractor using Conda Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/Introduction.md Recommended for Windows users and beginners. Installs the chemdataextractor package from the official conda channel. ```bash $ conda install -c chemdataextractor chemdataextractor ``` -------------------------------- ### Create a Document from a file Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/source_code_docs/doc.md Initializes a document from a file-like object, requiring binary mode. ```python with open('paper.html', 'rb') as f: doc = Document.from_file(f) ``` -------------------------------- ### Configuration and Settings Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/source_code_docs/doc.md Methods for loading settings and managing configurations. ```APIDOC ## set_config() ### Description Loads settings from a configuration file. ### NOTE This method is typically called when a Document instance is created. ``` -------------------------------- ### GetRequester Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/source_code_docs/scrape.md Handles making HTTP GET requests. ```APIDOC ## GetRequester ### Description Make a HTTP GET request. ### Method `make_request(session, url, **kwargs)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **requests.Response** - The response to the request. #### Response Example None ``` -------------------------------- ### Create a Sample Document with Heading and Paragraph Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/Introduction.md Instantiate a ChemDataExtractor Document with a Heading and Paragraph containing a boiling point to test parser functionality. ```python d = Document( Heading(u'Synthesis of 2,4,6-trinitrotoluene (3a)'), Paragraph(u'The procedure was followed to yield a pale yellow solid (b.p. 240 °C)') ) ``` -------------------------------- ### GET /chemdataextractor.text.bracket_level Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/source_code_docs/text.md Checks if a string contains balanced brackets. ```APIDOC ## GET /chemdataextractor.text.bracket_level ### Description Return 0 if string contains balanced brackets or no brackets. ### Parameters #### Request Body - **text** (string) - Required - The text to analyze. - **open** (set) - Optional - Set of opening bracket characters. - **close** (set) - Optional - Set of closing bracket characters. ``` -------------------------------- ### Create a Simple Document Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/examples/extracting_a_custom_property.ipynb Instantiate a ChemDataExtractor Document with a Heading and a Paragraph. ```python d = Document( Heading(u'Synthesis of 2,4,6-trinitrotoluene (3aാൻ'), Paragraph(u'The procedure was followed to yield a pale yellow solid (boiling point 240 °C)') ) ``` -------------------------------- ### GET /chemdataextractor.text.levenshtein Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/source_code_docs/text.md Calculates the Levenshtein distance between two strings. ```APIDOC ## GET /chemdataextractor.text.levenshtein ### Description Return the Levenshtein distance (edit difference) between two strings. ### Parameters #### Request Body - **s1** (string) - Required - The first string. - **s2** (string) - Required - The second string. - **allow_substring** (bool) - Optional - Whether to allow s1 to be a substring of s2. ### Response #### Success Response (200) - **distance** (int) - The calculated Levenshtein distance. ``` -------------------------------- ### chemdataextractor.relex.utils.KnuthMorrisPratt Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/source_code_docs/relex.md Yields all starting positions of copies of the pattern in the text. ```APIDOC ## FUNCTION chemdataextractor.relex.utils.KnuthMorrisPratt ### Description Yields all starting positions of copies of the pattern in the text. Calling conventions are similar to string.find, but its arguments can be lists or iterators. ### Parameters - **text** (iterable) - The text to search through. - **pattern** (iterable) - The pattern to search for. ``` -------------------------------- ### Switch to New Development Branch Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/Introduction.md Once your development branch is created, use this command to switch to it and begin making changes. ```bash $ git checkout [name_of_your_new_branch] ``` -------------------------------- ### GET /chemdataextractor.text.get_encoding Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/source_code_docs/text.md Determines the encoding of a byte string using UnicodeDammit. ```APIDOC ## GET /chemdataextractor.text.get_encoding ### Description Returns the encoding of a byte string. ### Parameters #### Request Body - **input_string** (string) - Required - Encoded byte string. - **guesses** (list [string]) - Optional - List of encoding guesses to prioritize. Default is ['utf-8']. - **is_html** (bool) - Optional - Whether the input is HTML. ``` -------------------------------- ### Create Document with Custom Config Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/examples/using_config_file.ipynb Import the `Document` and `Paragraph` classes to create a new document. Pass the initialized `Config` object to the `Document` constructor to apply custom settings. ```python from chemdataextractor import Document from chemdataextractor.doc.text import Paragraph doc = Document(Paragraph('Testing'), config=c) ``` -------------------------------- ### Update ChemDataExtractor Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/getting_started.md Commands to upgrade the toolkit installation using conda or pip. ```bash $ conda update -c chemdataextractor chemdataextractor ``` ```bash $ pip install --upgrade ChemDataExtractor ``` -------------------------------- ### Create Documents from Byte Strings Source: https://context7.com/cambridgemolecularengineering/chemdataextractor2/llms.txt Initialize documents from raw byte content, optionally specifying a filename to assist with format detection. ```python from chemdataextractor import Document # Read file content and create document contents = open('research_paper.html', 'rb').read() doc = Document.from_string(contents) # Or specify the filename to help with format detection doc = Document.from_string(contents, fname='paper.xml') # Access extracted chemical records for record in doc.records: print(record.serialize()) ``` -------------------------------- ### chemdataextractor.doc.text.Span Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/source_code_docs/doc.md Represents a segment of text within a sentence, defined by its start and end offsets. ```APIDOC ## Class: chemdataextractor.doc.text.Span ### Description A text span within a sentence. ### Method __init__ ### Parameters * **text** (str) - The text contained by this span. * **start** (int) - The start offset of this token in the original text. * **end** (int) - The end offset of this token in the original text. ### Properties * **text**: str - The text content of this span. * **start**: int - The start offset of this token in the original text. * **end**: int - The end offset of this token in the original text. * **length**: int - The offset length of this span in the original text. ``` -------------------------------- ### Agent Loader Initialization Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/tests/data/rsc/10.1039_C6OB02074G.html Loads the agent script and initializes monitoring markers. ```javascript loader:[function(t,e,n){function r(){if(!g++){var t=y.info=NREUM.info,e=u.getElementsByTagName("script")[0];if(t&&t.licenseKey&&t.applicationID&&e){c(w,function(e,n){t[e]||(t[e]=n)});var n="https"===m.split(":")[0]||t.sslForHttp;y.proto=n?"https://":"http://",s("mark",["onload",a()],null,"api");var r=u.createElement("script");r.src=y.proto+t.agent,e.parentNode.insertBefore(r,e)}}}function o(){"complete"===u.readyState&&i()}function i(){s("mark",["domContent",a()],null,"api")}function a(){return(new Date).getTime()}var s=t("handle"),c=t(15),f=window,u=f.document,d="addEventListener",l="attachEvent",p=f.XMLHttpRequest,h=p&&p.prototype;NREUM.o={ST:setTimeout,CT:clearTimeout,XHR:p,REQ:f.Request,EV:f.Event,PR:f.Promise,MO:f.MutationObserver},t(12);var m=""+location,w={beacon:"bam.nr-data.net",errorBeacon:"bam.nr-data.net",agent:"js-agent.newrelic.com/nr-974.min.js"},v=p&&h&&h[d]&&!/CriOS/.tes ``` -------------------------------- ### Create a Document from a byte string Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/source_code_docs/doc.md Initializes a document from the raw byte content of a file. ```python contents = open('paper.html', 'rb').read() doc = Document.from_string(contents) ``` -------------------------------- ### Property Definitions Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/source_code_docs/doc.md Retrieves definitions of properties, including the quantity, specifier, start, and end indices. ```APIDOC ## GET /api/properties/definitions ### Description Return specifier definitions from a sentence. A definition consists of: a) A definition – The quantity being defined e.g. “Curie Temperature” b) A specifier – The symbol used to define the quantity e.g. “Tc” c) Start – The index of the starting point of the definition d) End – The index of the end point of the definition ### Returns: list – The specifier definitions ``` -------------------------------- ### Configuration Management Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/source_code_docs/chemdataextractor.md Details on how to read and write configuration files using the Config class. ```APIDOC ## Config Class ### Description Read and write to config file. A config object is essentially a string key-value store that can be treated like a dictionary. ### Class Definition `chemdataextractor.config.Config(path=None)` ### Parameters * **path** (*string*) – (Optional) Path to config file location. ### Example Usage ```python c = Config() c['foo'] = 'bar' print(c['foo']) c = Config('~/matt/anotherconfig.yml') c['where'] = 'in a different file' ``` ### Properties * **path** - The path to the config file. ### Methods * **clear()** - Clear all values from config. ``` -------------------------------- ### Update ChemDataExtractor using Pip Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/Introduction.md Upgrades an existing ChemDataExtractor installation to the latest version using pip. ```bash $ pip install --upgrade ChemDataExtractor ``` -------------------------------- ### Update ChemDataExtractor using Conda Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/Introduction.md Upgrades an existing ChemDataExtractor installation to the latest version using conda. ```bash $ conda update -c chemdataextractor chemdataextractor ``` -------------------------------- ### Create a Sample ChemDataExtractor Document Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/introduction/new_property.md Instantiate a ChemDataExtractor Document with a Heading and a Paragraph containing a boiling point. This serves as a test case for custom property extraction. ```python d = Document( Heading(u'Synthesis of 2,4,6-trinitrotoluene (3a લાગ)\\'), Paragraph(u'The procedure was followed to yield a pale yellow solid (boiling point 240 °C)') ) ``` -------------------------------- ### New Relic API Initialization Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/tests/data/rsc/10.1039_C6OB02074G.html Initializes the New Relic API and sets up interaction tracking. ```javascript his}}var i=t("handle"),a=t(15),s=t(16),c=t("ee").get("tracer"),f=NREUM;"undefined"==typeof window.newrelic&&(newrelic=f);var u=["setPageViewName","setCustomAttribute","setErrorHandler","finished","addToTrace","inlineHit"],d="api-",l=d+"ixn-";a(u,function(t,e){f[e]=o(d+e,!0,"api")}),f.addPageAction=o(d+"addPageAction",!0),e.exports=newrelic,f.interaction=function(){return(new r).get()};var p=r.prototype={createTracer:function(t,e){var n={},r=this,o="function"==typeof e;return i(l+"tracer",[Date.now(),t,n],r),function(){if(c.emit((o?"":"no-")+"fn-start",[Date.now(),r,o],n),o)try{return e.apply(this,arguments)}finally{c.emit("fn-end",[Date.now()],n)}}}};a("setName,setAttribute,save,ignore,onEnd,getContext,end,get".split(","),function(t,e){p[e]=o(l+e)}),newrelic.noticeError=function(t){"string"==typeof t&&(t=new Error(t)),i("err",[t,(new Date).getTime()])}},{}] ``` -------------------------------- ### ElsevierSearchScraper Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/source_code_docs/scrape.md Scraper for Elsevier search results. It can be used to make HTTP GET requests and process the responses. ```APIDOC ## ElsevierSearchScraper ### Description Scraper for Elsevier search results. ### Methods #### make_request(url) Make a HTTP GET request. - **Parameters:** - **url** (string) - The URL to get. - **Returns:** The response to the request. - **Return type:** requests.Response #### run(url) Request URL, scrape response and return an EntityList. ### Classes #### entity alias of [`ElsevierSearchDocument`](#chemdataextractor.scrape.pub.elsevier.ElsevierSearchDocument) ``` -------------------------------- ### Initialize New Relic Browser Agent Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/tests/data/relex/curie_training_set/c1jm13879k.html Loads and initializes the New Relic browser agent, setting up performance monitoring. Requires specific NREUM info. ```javascript function r(){if(!x++){var t=g.info=NREUM.info,e=p.getElementsByTagName("script")[0];if(setTimeout(u.abort,3e4),!(t&&t.licenseKey&&t.applicationID&&e))return u.abort();f(y,function(e,n){t[e]||(t[e]=n)}),s("mark",\["onload",a()+g.offset\],null,"api");var n=p.createElement("script");n.src="https://"+t.agent,e.parentNode.insertBefore(n,e)}}function o(){"complete"===p.readyState&&i()}function i(){s("mark",\["domContent",a()+g.offset\],null,"api")}function a(){return E.exists&&performance.now?Math.round(performance.now()):(c=Math.max((new Date).getTime(),c))-g.offset}var c=(new Date).getTime(),s=t("handle"),f=t(19),u=t("ee"),d=window,p=d.document,h="addEventListener",l="attachEvent",m=d.XMLHttpRequest,v=m&&m.prototype;NREUM.o={ST:setTimeout,CT:clearTimeout,XHR:m,REQ:d.Request,EV:d.Event,PR:d.Promise,MO:d.MutationObserver};var w=""+location,y={beacon:"bam.nr-data.net",errorBeacon:"bam.nr-data.net",agent:"js-agent.newrelic.com/nr-spa-1026.min.js"},b=m&&v&&v[h]&&!/CriOS/.test(navigator.userAgent),g=e.exports={offset:c,now:a,origin:w,features:{},xhrWrappable:b};t(16),p[h]?(p[h]("DOMContentLoaded",i,!1),d[h]("load",r,!1)):(p[l]("onreadystatechange",o),d[l]("onload",r)),s("mark",\["firstbyte",c\],null,"api");var x=0,E=t(21)} ``` -------------------------------- ### Retrieve Combined Document Records Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/introduction/finding_records.md Get merged chemical records for the entire document to resolve interdependencies. ```python >>> doc.records.serialize() [{'Compound': {'names': ['5,10,15,20-Tetra(4-carboxyphenyl)porphyrin'], 'labels': ['3']}}, {'Compound': {'names': ['THF', 'Tetrahydrofuran']}}, {'MeltingPoint': {'raw_value': '90', 'raw_units': '°C', 'value': [90.0], 'units': 'Celsius^(1.0)', 'compound': {'Compound': {'names': ['5,10,15,20-Tetra(4-carboxyphenyl)porphyrin'], 'labels': ['3']}}}}] ``` -------------------------------- ### Initialize Google Analytics Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/tests/data/rsc/searchresults.html Asynchronously loads the Google Analytics script into the document head. ```javascript // ``` -------------------------------- ### Instrument Fetch API Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/tests/data/relex/curie_training_set/c3nr33950e.html Wraps the global fetch API to emit events at the start and end of requests. ```javascript function r(t,e,n){var r=t[e];"function"==typeof r&&(t[e]=function(){var t=r.apply(this,arguments);return o.emit(n+"start",arguments,t),t.then(function(e){return o.emit(n+"end",[null,e],t),e},function(e){throw o.emit(n+"end",[e],t),e})})}var o=t("ee").get("fetch"),i=t(19);e.exports=o;var a=window,c="fetch-",s=c+"body-",f=["arrayBuffer","blob","json","text","formData"],u=a.Request,d=a.Response,p=a.fetch,h="prototype";u&&d&&p&&(i(f,function(t,e){r(u[h],e,s),r(d[h],e,s)}),r(a,"fetch",c),o.on(c+"end",function(t,e){var n=this;e?e.clone().arrayBuffer().then(function(t){n.rxSize=t.byteLength,o.emit(c+"done",[null,e],n)}):o.emit(c+"done",[t],n)})) ``` -------------------------------- ### Define Custom Temperature Model with Template Parsers Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/examples/template_parsers.ipynb Create a custom model inheriting from TemperatureModel and include QuantityModelTemplateParser and MultiQuantityModelTemplateParser in its parsers list. This example shows how to define a specifier and compound for the model. ```python from chemdataextractor.model.units.temperature import TemperatureModel from chemdataextractor.parse.elements import I from chemdataextractor.model import Compound, StringType, ModelType from chemdataextractor.doc import Sentence class MyTemperatureModel(TemperatureModel): specifier = StringType(parse_expression=I('Tc'), required=True) compound = ModelType(Compound, required=True) parsers = [QuantityModelTemplateParser(), MultiQuantityModelTemplateParser()] ``` -------------------------------- ### Define a Curie Temperature Model Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/examples/using_snowball.ipynb Example of defining a quaternary relationship model by specifying expressions and entity types. ```python class CurieTemperature(TemperatureModel): specifier_expression =((I('Curie') + I('temperature')) | I('Tc')).add_action(join) specifier = StringType(parse_expression=specifier_expression, required=True, contextual=True, updatable=True) compound = ModelType(Compound, required=True, contextual=True, updatable=False) ``` -------------------------------- ### Instantiate and use Cleaner for HTML Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/docs/source_code_docs/scrape.md Demonstrates how to create a Cleaner instance and use its clean_markup method to process an HTML string. The cleaner removes script tags and cleans up other markup. ```python cleaner = Cleaner() htmlstring = '

Some text

' print(cleaner.clean_markup(htmlstring)) ``` -------------------------------- ### Function Wrapper for Instrumentation Source: https://github.com/cambridgemolecularengineering/chemdataextractor2/blob/master/tests/data/relex/curie_training_set/b806499g.html Wraps a function to add instrumentation for start, end, and error events. Useful for performance monitoring. ```javascript function r(t){return!(t&&t instanceof Function&&t.apply&&!t[a])}var o=t("ee"),i=t(20),a="nr@original",c=Object.prototype.hasOwnProperty,s=!1;e.exports=function(t,e){function n(t,e,n,o){function nrWrapper(){var r,a,c,s;try{a=this,r=i(arguments),c="function"==typeof n?n(r,a):n||{}}catch(f){p([f,"",[r,a,o]],c)}u(e+"start",[r,a,o],c);try{return s=t.apply(a,r)}catch(d){throw u(e+"err",[r,a,d],c),d}finally{u(e+"end",[r,a,s],c)}}return r(t)?t:(e||"",nrWrapper[a]=t,d(t,nrWrapper),nrWrapper)}function f(t,e,o,i){o||"",o.charAt(0);for(s=0;s