-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add parser for glass transition temperature #13
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
|
||
from .common import delim | ||
from ..utils import first | ||
from ..model import Compound, UvvisSpectrum, UvvisPeak, QuantumYield, FluorescenceLifetime, MeltingPoint | ||
from ..model import Compound, UvvisSpectrum, UvvisPeak, QuantumYield, FluorescenceLifetime, MeltingPoint, GlassTransition | ||
from ..model import ElectrochemicalPotential, IrSpectrum, IrPeak | ||
from .actions import join, merge, fix_whitespace | ||
from .base import BaseParser | ||
|
@@ -201,6 +201,12 @@ def split_uvvis_shape(tokens, start, result): | |
temp_with_optional_units + ZeroOrMore(delims.hide() + temp_with_optional_units) | ||
)('melting_point_cell') | ||
|
||
glass_transition_title = R('^T(g\.)$', re.I) | W('T') + R('^(g\.)?$') | ||
glass_transition_heading = (glass_transition_title.hide() + delims.hide() + Optional(temp_units))('glass_transition_heading') | ||
glass_transition_cell = ( | ||
temp_with_optional_units + ZeroOrMore(delims.hide() + temp_with_optional_units) | ||
)('glass_transition_cell') | ||
|
||
caption_context = Group(subject_phrase | solvent_phrase | temp_phrase)('caption_context') | ||
|
||
|
||
|
@@ -241,11 +247,12 @@ def interpret(self, result, start, end): | |
solvent = first(result.xpath('./name/text()')) | ||
if solvent is not None: | ||
context = {'solvent': solvent} | ||
c.melting_points = [MeltingPoint(context)] | ||
c.quantum_yields = [QuantumYield(context)] | ||
c.fluorescence_lifetimes = [FluorescenceLifetime(context)] | ||
c.electrochemical_potentials = [ElectrochemicalPotential(context)] | ||
c.uvvis_spectra = [UvvisSpectrum(context)] | ||
c.melting_points = [MeltingPoint(**context)] | ||
c.glass_transitions = [GlassTransition(**context)] | ||
c.quantum_yields = [QuantumYield(**context)] | ||
c.fluorescence_lifetimes = [FluorescenceLifetime(**context)] | ||
c.electrochemical_potentials = [ElectrochemicalPotential(**context)] | ||
c.uvvis_spectra = [UvvisSpectrum(**context)] | ||
if c.serialize(): | ||
yield c | ||
|
||
|
@@ -261,10 +268,11 @@ def interpret(self, result, start, end): | |
'temperature': first(result.xpath('./value/text()')), | ||
'temperature_units': first(result.xpath('./units/text()')) | ||
} | ||
c.quantum_yields = [QuantumYield(context)] | ||
c.fluorescence_lifetimes = [FluorescenceLifetime(context)] | ||
c.electrochemical_potentials = [ElectrochemicalPotential(context)] | ||
c.uvvis_spectra = [UvvisSpectrum(context)] | ||
# RBT Same problem as before missing **? | ||
c.quantum_yields = [QuantumYield(**context)] | ||
c.fluorescence_lifetimes = [FluorescenceLifetime(**context)] | ||
c.electrochemical_potentials = [ElectrochemicalPotential(**context)] | ||
c.uvvis_spectra = [UvvisSpectrum(**context)] | ||
yield c | ||
|
||
|
||
|
@@ -278,11 +286,13 @@ def interpret(self, result, start, end): | |
solvent = first(result.xpath('./name/text()')) | ||
if solvent is not None: | ||
context = {'solvent': solvent} | ||
c.melting_points = [MeltingPoint(context)] | ||
c.quantum_yields = [QuantumYield(context)] | ||
c.fluorescence_lifetimes = [FluorescenceLifetime(context)] | ||
c.electrochemical_potentials = [ElectrochemicalPotential(context)] | ||
c.uvvis_spectra = [UvvisSpectrum(context)] | ||
# RBT (Added ** to context) | ||
c.melting_points = [MeltingPoint(**context)] | ||
c.glass_transitions = [GlassTransition(**context)] | ||
c.quantum_yields = [QuantumYield(**context)] | ||
c.fluorescence_lifetimes = [FluorescenceLifetime(**context)] | ||
c.electrochemical_potentials = [ElectrochemicalPotential(**context)] | ||
c.uvvis_spectra = [UvvisSpectrum(**context)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch on the missing |
||
if c.serialize(): | ||
yield c | ||
|
||
|
@@ -597,6 +607,37 @@ def interpret(self, result, start, end): | |
yield c | ||
|
||
|
||
class GlassTransitionHeadingParser(BaseParser): | ||
"""""" | ||
root = glass_transition_heading | ||
|
||
def interpret(self, result, start, end): | ||
"""""" | ||
glass_transition_units = first(result.xpath('./units/text()')) | ||
c = Compound() | ||
if glass_transition_units: | ||
c.glass_transitions.append( | ||
GlassTransition(units=glass_transition_units) | ||
) | ||
yield c | ||
|
||
class GlassTransitionCellParser(BaseParser): | ||
"""""" | ||
root = glass_transition_cell | ||
|
||
def interpret(self, result, start, end): | ||
"""""" | ||
c = Compound() | ||
for tg in result.xpath('./temp'): | ||
c.glass_transitions.append( | ||
GlassTransition( | ||
value=first(mp.xpath('./value/text()')), | ||
units=first(mp.xpath('./units/text()')) | ||
) | ||
) | ||
if c.glass_transition: | ||
yield c | ||
|
||
class ElectrochemicalPotentialHeadingParser(BaseParser): | ||
"""""" | ||
root = electrochemical_potential_heading | ||
|
@@ -650,6 +691,13 @@ def interpret(self, result, start, end): | |
if context: | ||
c.melting_points = [MeltingPoint(**context)] | ||
temp = first(result.xpath('./temp_phrase')) | ||
if temp is not None: | ||
context['temperature'] = first(temp.xpath('./temp/value/text()')) | ||
context['temperature_units'] = first(temp.xpath('./temp/units/text()')) | ||
# Glass transition temperature shouldn't have contextual temperature | ||
if context: | ||
c.glass_transitions = [GlassTransition(**context)] | ||
temp = first(result.xpath('./temp_phrase')) | ||
if temp is not None: | ||
context['temperature'] = first(temp.xpath('./temp/value/text()')) | ||
context['temperature_units'] = first(temp.xpath('./temp/units/text()')) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
chemdataextractor.parse.nmr | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
NMR text parser. | ||
|
||
:copyright: Copyright 2016 by Matt Swain. | ||
:license: MIT, see LICENSE file for more details. | ||
""" | ||
|
||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
import logging | ||
import re | ||
|
||
from chemdataextractor.parse.cem import cem, chemical_label, lenient_chemical_label, solvent_name | ||
from chemdataextractor.parse.common import lbrct, dt, rbrct, hyphen | ||
from ..utils import first | ||
from ..model import Compound, GlassTransition | ||
from .actions import merge, join | ||
from .base import BaseParser | ||
from .elements import W, I, R, Optional, Any, OneOrMore, Not, ZeroOrMore | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
prefix = Optional(I('a')).hide() + (Optional(lbrct) + W('Tg') + Optional(rbrct) | I('glass') + Optional(I('transition')) + Optional((I('temperature') | I('range') | I('temp.'))) | W('transition') + Optional((I('temperature') | I('range') | I('temp.')))).hide() + Optional(lbrct + W('Tg') + rbrct) + Optional(W('=') | I('of') | I('was') | I('is') | I('at')).hide() + Optional(I('in') + I('the') + I('range') + Optional(I('of')) | I('about') | ('around') | I('ca') | I('ca.')).hide() | ||
#prefix = Optional(I('a')).hide() + (Optional(lbrct) + W('Tg') + Optional(rbrct) | I('glass') + Optional(I('transition')) + Optional((I('temperature') | I('range') | I('temp.')))).hide() + Optional(lbrct + W('Tg') + rbrct) + Optional(W('=') | I('of') | I('was') | I('is') | I('at')).hide() + Optional(I('in') + I('the') + I('range') + Optional(I('of')) | I('about') | ('around') | I('ca') | I('ca.')).hide() | ||
|
||
delim = R('^[:;\.,]$') | ||
|
||
# TODO: Consider allowing degree symbol to be optional. The prefix should be restrictive enough to stop false positives. | ||
units = (W('°') + Optional(R('^[CFK]\.?$')) | W('K\.?'))('units').add_action(merge) | ||
|
||
joined_range = R('^[\+\-–−]?\d+(\.\d+)?[\-–−~∼˜]\d+(\.\d+)?$')('value').add_action(merge) | ||
spaced_range = (R('^[\+\-–−]?\d+(\.\d+)?$') + Optional(units).hide() + (R('^[\-–−~∼˜]$') + R('^[\+\-–−]?\d+(\.\d+)?$') | R('^[\+\-–−]\d+(\.\d+)?$')))('value').add_action(merge) | ||
to_range = (R('^[\+\-–−]?\d+(\.\d+)?$') + Optional(units).hide() + (I('to') + R('^[\+\-–−]?\d+(\.\d+)?$') | R('^[\+\-–−]\d+(\.\d+)?$')))('value').add_action(join) | ||
temp_range = (Optional(R('^[\-–−]$')) + (joined_range | spaced_range | to_range))('value').add_action(merge) | ||
temp_value = (Optional(R('^[~∼˜\<\>]$')) + Optional(R('^[\-–−]$')) + R('^[\+\-–−]?\d+(\.\d+)?$'))('value').add_action(merge) | ||
temp = Optional(lbrct).hide() + (temp_range | temp_value)('value') + Optional(rbrct).hide() | ||
|
||
tg = (prefix + Optional(delim).hide() + temp + units)('tg') | ||
|
||
bracket_any = lbrct + OneOrMore(Not(tg) + Not(rbrct) + Any()) + rbrct | ||
|
||
cem_tg_phrase = (Optional(cem) + Optional(I('having')).hide() + Optional(delim).hide() + Optional(bracket_any).hide() + Optional(delim).hide() + Optional(lbrct) + tg + Optional(rbrct))('tg_phrase') | ||
|
||
obtained_tg_phrase = ((cem | chemical_label) + (I('is') | I('are') | I('was')).hide() + (I('measured') | I('obtained') | I('yielded')).hide() + ZeroOrMore(Not(tg) + Not(cem) + Any()).hide() + tg)('tg_phrase') | ||
|
||
#tg_phrase = cem_tg_phrase | method1_phrase | method2_phrase | method3_phrase | obtained_tg_phrase | ||
tg_phrase = cem_tg_phrase | obtained_tg_phrase | ||
|
||
|
||
class TgParser(BaseParser): | ||
"""""" | ||
root = tg_phrase | ||
|
||
#print ('outside parser', tg_phrase, type(tg_phrase)) | ||
|
||
def interpret(self, result, start, end): | ||
compound = Compound( | ||
glass_transitions=[ | ||
GlassTransition( | ||
value=first(result.xpath('./tg/value/text()')), | ||
units=first(result.xpath('./tg/units/text()')) | ||
) | ||
] | ||
) | ||
cem_el = first(result.xpath('./cem')) | ||
if cem_el is not None: | ||
compound.names = cem_el.xpath('./name/text()') | ||
compound.labels = cem_el.xpath('./label/text()') | ||
yield compound | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems this problem occurs when it is attempted to merge the 'contextual' information from a compound record into another one, but the 'contextual' record also happens to contain a name/label/role. This can happen when merging in information from table footnotes or caption - the idea is to merge e.g. a solvent into the property in the table cell that references it. But sometimes there is an actual compound named in the footnote. This fix seems to work well - just ignoring the string-based properties - which are name/label/role. However,
unicode
is python 2 only - this needs to besix.text_type
for python 2 and 3 compatibility. In future, this wholemerge_contextual
method needs refactoring to be more agnostic of the model schema.