Skip to content

Way to disable numerical parsing of s-expressions? #23

@khannan-livefront

Description

@khannan-livefront

Describe the bug
I'm working with s-expressions from an NLP parser, and I'm having difficulty parsing items as a string into symbols without raising float errors.

For the following s-expression string:

(ROOT (NP (FRAG (CC And) (-LRB- -LRB-) (NP (NNP Gen.) (CD 32) (. .) (CD 1.)) (-RRB- -RRB-) (PP (IN in) (NP (NP (DT a) (NNP Vision)) (PP (IN of) (NP (NNPS Angels)))))) (: :) (CC And) (PP (IN to) (NP (NP (NNP Moses)) (-LRB- -LRB-) (NP (NP (NN Exod.)) (NP (CD 3.2.))) (-RRB- -RRB-))) (PP (IN in) (NP (NP (DT the) (NN apparition)) (PP (IN of) (NP (DT a) (NN flame)))))))

The SXP parser errors with:

ArgumentError: invalid value for Float(): "1."

To reproduce
Steps to reproduce the behavior:

  1. copy this code:
s_expression = "(ROOT (NP (FRAG (CC And) (LRB -LRB-) (NP (NNP Gen.) (CD 32) (PUNCTUATION .) (CD 1.)) (RRB -RRB-) (PP (IN in) (NP (NP (DT a) (NNP Vision)) (PP (IN of) (NP (NNPS Angels)))))) (: :) (CC And) (PP (IN to) (NP (NP (NNP Moses)) (LRB -LRB-) (NP (NP (NN Exod.)) (NP (CD 3.2.))) (RRB -RRB-))) (PP (IN in) (NP (NP (DT the) (NN apparition)) (PP (IN of) (NP (DT a) (NN flame)))))))"

SXP.read(s_expression)

  1. See error

Expected behavior
SXP parses the nodes as strings rather than as numericals. I want characters like periods to be seen as strings.

Desktop (please complete the following information):

  • OS: [Mac OS Monteray]

Additional context
It appears a possible fix for our problem is monkey patching the gem to remove numerical parsing altogether:

module SXP
  class Reader
    class Basic < Reader
      ## Monkey patch, we don't need numerics
      # @return [Object]
      def read_atom
        case buffer = read_literal
        when '.'      then buffer.to_sym
        else buffer.to_sym
        end
      end
    end
  end
end

I would like your advice on if that's correct and insight into if there is a way to fix this within the gem, perhaps as a form of configuration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions