Closed croxis closed 9 years ago
Is this happening while trying to run the code as is (like in encode.py or decode.py) or is this in some new code you wrote yourself?
Manatext is basically a wrapper for a pair of a string and a list of Manacosts, with each manacost's position preserved in the string by a special character (currently, $). It doesn't actually support string operations, just a few encoding and decoding helpers that it can pass through to the manacosts.
I thought about implementing the standard string interface, but I realized it was basically easier to just know that the Manatext has a text field and send all of the operations through to that. So, for example, if I want to do:
mt = Manatext(foo)
mt = mt.replace('counter', 'uncast')
I'd instead write:
mt = Manatext(foo)
mt.text = mt.text.replace('counter', 'uncast')
It's hacky, and you have to know there will be $s in the test instead of actual mana strings. If you want to process those you can always encode it, do the processing on the string, and then make a new Manatext out of it.
If there's an easy way to support the string interface without writing much code I'd consider doing that to make things cleaner. I did start doing that before but stopped because it was unnecessary work and I wasn't really sure how to handle things in a way that would make anything materially more powerful or more usable.
On a side note, I would like to support python 3 in general. I have in installed (stock ubuntu 14.04) but trying to use it just complains that all of my prints are in the python 2 syntax. How are you getting around that?
Odd. I'm basically trying to reimplement encoder/decoder but using just strings instead of files. I must be doing something wrong then. I'll go over my code again tomorrow.
On Wed, Jul 29, 2015, 19:25 Bill notifications@github.com wrote:
Is this happening while trying to run the code as is (like in encode.py or decode.py) or is this in some new code you wrote yourself?
Manatext is basically a wrapper for a pair of a string and a list of Manacosts, with each manacost's position preserved in the string by a special character (currently, $). It doesn't actually support string operations, just a few encoding and decoding helpers that it can pass through to the manacosts.
I thought about implementing the standard string interface, but I realized it was basically easier to just know that the Manatext has a text field and send all of the operations through to that. So, for example, if I want to do:
mt = Manatext(foo) mt = mt.replace('counter', 'uncast')
I'd instead write:
mt = Manatext(foo) mt.text = mt.text.replace('counter', 'uncast')
It's hacky, and you have to know there will be $s in the test instead of actual mana strings. If you want to process those you can always encode it, do the processing on the string, and then make a new Manatext out of it.
If there's an easy way to support the string interface without writing much code I'd consider doing that to make things cleaner. I did start doing that before but stopped because it was unnecessary work and I wasn't really sure how to handle things in a way that would make anything materially more powerful or more usable.
On a side note, I would like to support python 3 in general. I have in installed (stock ubuntu 14.04) but trying to use it just complains that all of my prints are in the python 2 syntax. How are you getting around that?
— Reply to this email directly or view it on GitHub https://github.com/billzorn/mtgencode/issues/1#issuecomment-126162467.
You should be able to just pull out the main loop, as I did to write the constructor for CBOW:
for card_src in text.split(utils.cardsep):
if card_src:
card = cardlib.Card(card_src)
To get cards, all you need to do is chop your string up into the right sized pieces. Once you have cards, you can do whatever you want with them.
What are you building? If it's a commonly desirable application I could build it as a new script, or possibly integrate it into encode or decode by adding some more flags.
Oh, and it just occurred to me looking at the title of the issue, if you're invoking things from lib/transforms.py, you can't pass a Manatext in directly because they all expect strings. You'll have to do:
mt = Manatext(foo)
mt.text = transforms.text_pass_1_strip_rt(mt.text)
If you look, lib/cardlib.py pulls the string out of the manatext before invoking any transform passes on it.
Yup, I was grabbing card.text, not card.text.text. I feel daft!
In python 3 Manatext is throwing Attribute errors because it has no replace() functions. My hunch is that it is working in python 2 because you are using old style classes. Any possibility on making it new-class compatible?