<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Parse a description into components
This notebook requires at least version 0.8.8.
Step1:  We have some text
Step2:  To read this with striplog, we need to define a Lexicon. This is a dictionary-like object full of regular expressions, which acts as a bridge between this unstructured description and a dictionary-like Component object which striplog wants. The Lexicon also contains abbreviations for converting abbreviated text like cuttings descriptions into expanded words.
A Lexicon to read only this text might look like
Step3:  Now we can parse the text with it
Step4:  But this is obviously a bit of a pain to make and maintain. So instead of definining a Lexicon from scratch, we'll modify the default one
Step5:  Parsing with this yields the same results as before...
Step6:  ...but we can parse more things now
<ASSISTANT_TASK:>
Python Code:
import striplog
striplog.__version__
Explanation: Parse a description into components
This notebook requires at least version 0.8.8.
End of explanation
text = "wet silty fine sand with tr clay"
Explanation: We have some text:
End of explanation
from striplog import Lexicon
lex_dict = {
    'lithology': ['sand', 'clay'],
    'grainsize': ['fine'],
    'modifier':  ['silty'],
    'amount':    ['trace'],
    'moisture':  ['wet', 'dry'],
    'abbreviations': {'tr': 'trace'},
    'splitters': ['with'],
    'parts_of_speech': {'noun': ['lithology'],
                        'adjective': ['grainsize', 'modifier', 'moisture'],
                        'subordinate': ['amount'],
                       }
}
lexicon = Lexicon(lex_dict)
Explanation: To read this with striplog, we need to define a Lexicon. This is a dictionary-like object full of regular expressions, which acts as a bridge between this unstructured description and a dictionary-like Component object which striplog wants. The Lexicon also contains abbreviations for converting abbreviated text like cuttings descriptions into expanded words.
A Lexicon to read only this text might look like:
End of explanation
from striplog import Interval
Interval._parse_description(text, lexicon=lexicon, max_component=3, abbreviations=True)
Explanation: Now we can parse the text with it:
End of explanation
# Make and expand the lexicon.
lexicon = Lexicon.default()
# Add moisture words (or could add as other 'modifiers').
lexicon.moisture = ['wet(?:tish)?', 'dry(?:ish)?']
lexicon.parts_of_speech['adjective'] += ['moisture']
# Add the comma as component splitter.
lexicon.splitters += [', ']
Explanation: But this is obviously a bit of a pain to make and maintain. So instead of definining a Lexicon from scratch, we'll modify the default one:
End of explanation
Interval._parse_description(text, lexicon=lexicon, max_component=3)
Explanation: Parsing with this yields the same results as before...
End of explanation
Interval._parse_description("Coarse sandstone with minor limestone", lexicon=lexicon, max_component=3)
Explanation: ...but we can parse more things now:
End of explanation
<END_TASK>