How to use the textblob.nltk.corpus.reader.framenet.FramenetError function in textblob

To help you get started, we’ve selected a few textblob examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sloria / TextBlob / textcorpus / reader / framenet.py View on Github external
- 'name'
                                - 'feID' (optional)

        :param fn_docid: The Framenet id number of the document
        :type fn_docid: int
        :return: Information about the annotated document
        :rtype: dict
        """
        try:
            xmlfname = self._fulltext_idx[fn_docid].filename
        except TypeError:  # happens when self._fulltext_idx == None
            # build the index
            self._buildcorpusindex()
            xmlfname = self._fulltext_idx[fn_docid].filename
        except KeyError:  # probably means that fn_docid was not in the index
            raise FramenetError("Unknown document id: {0}".format(fn_docid))

        # construct the path name for the xml file containing the document info
        locpath = os.path.join(
            "{0}".format(self._root), self._fulltext_dir, xmlfname)

        # Grab the top-level xml element containing the fulltext annotation
        elt = XMLCorpusView(locpath, 'fullTextAnnotation')[0]
        return self._handle_fulltextannotation_elt(elt)
github sloria / TextBlob / textcorpus / reader / framenet.py View on Github external
frame = self.frame_by_name(frame).ID
                rels = [self._frel_idx[frelID] for frelID in self._frel_f_idx[frame]]
        
            # filter by 'type'
            if type is not None:
                rels = [rel for rel in rels if rel.type is type]
        elif type is not None:
            # lookup by 'type'
            rels = type.frameRelations
        else:
            rels = self._frel_idx.values()
        
        # filter by 'frame2'
        if frame2 is not None:
            if frame is None:
                raise FramenetError("frame_relations(frame=None, frame2=) is not allowed")
            if not isinstance(frame2, int):
                if isinstance(frame2, dict):
                    frame2 = frame2.ID
                else:
                    frame2 = self.frame_by_name(frame2).ID
            if frame==frame2:
                raise FramenetError("The two frame arguments to frame_relations() must be different frames")
            rels = [rel for rel in rels if rel.superFrame.ID==frame2 or rel.subFrame.ID==frame2]
        
        return PrettyList(sorted(rels, 
                key=lambda frel: (frel.type.ID, frel.superFrameName, frel.subFrameName)))
github sloria / TextBlob / textcorpus / reader / framenet.py View on Github external
Also see the ``frame()`` function for details about what is
        contained in the dict that is returned.
        """

        # get the name of the frame with this id number
        try:
            fentry = self._frame_idx[fn_fid]
            if '_type' in fentry:
                return fentry   # full frame object is cached
            name = fentry['name']
        except TypeError:
            self._buildframeindex()
            name = self._frame_idx[fn_fid]['name']
        except KeyError:
            raise FramenetError('Unknown frame id: {0}'.format(fn_fid))

        return self.frame_by_name(name, ignorekeys, check_cache=False)
github sloria / TextBlob / textcorpus / reader / framenet.py View on Github external
"""
        
        if check_cache and fn_fname in self._cached_frames:
            return self._frame_idx[self._cached_frames[fn_fname]]
        elif not self._frame_idx:
            self._buildframeindex()
        
        # construct the path name for the xml file containing the Frame info
        locpath = os.path.join(
            "{0}".format(self._root), self._frame_dir, fn_fname + ".xml")
        #print(locpath, file=sys.stderr)
        # Grab the xml for the frame
        try:
            elt = XMLCorpusView(locpath, 'frame')[0]
        except IOError:
            raise FramenetError('Unknown frame: {0}'.format(fn_fname)) 

        fentry = self._handle_frame_elt(elt, ignorekeys)
        assert fentry
        
        # INFERENCE RULE: propagate lexical semtypes from the frame to all its LUs
        for st in fentry.semTypes:
            if st.rootType.name=='Lexical_type':
                for lu in fentry.lexUnit.values():
                    if st not in lu.semTypes:
                        lu.semTypes.append(st)
        
        
        self._frame_idx[fentry.ID] = fentry
        self._cached_frames[fentry.name] = fentry.ID
        '''
        # now set up callables to resolve the LU pointers lazily. 
github sloria / TextBlob / textcorpus / reader / framenet.py View on Github external
# lookup by 'type'
            rels = type.frameRelations
        else:
            rels = self._frel_idx.values()
        
        # filter by 'frame2'
        if frame2 is not None:
            if frame is None:
                raise FramenetError("frame_relations(frame=None, frame2=) is not allowed")
            if not isinstance(frame2, int):
                if isinstance(frame2, dict):
                    frame2 = frame2.ID
                else:
                    frame2 = self.frame_by_name(frame2).ID
            if frame==frame2:
                raise FramenetError("The two frame arguments to frame_relations() must be different frames")
            rels = [rel for rel in rels if rel.superFrame.ID==frame2 or rel.subFrame.ID==frame2]
        
        return PrettyList(sorted(rels, 
                key=lambda frel: (frel.type.ID, frel.superFrameName, frel.subFrameName)))
github sloria / TextBlob / textcorpus / reader / framenet.py View on Github external
"""
        Augment the LU information that was loaded from the frame file 
        with additional information from the LU file.
        """
        fn_luid = lu.ID

        fname = "lu{0}.xml".format(fn_luid)
        locpath = os.path.join("{0}".format(self._root), self._lu_dir, fname)
        #print(locpath, file=sys.stderr)
        if not self._lu_idx:
            self._buildluindex()
        
        try:
            elt = XMLCorpusView(locpath, 'lexUnit')[0]
        except IOError:
            raise FramenetError('Unknown LU id: {0}'.format(fn_luid))

        lu2 = self._handle_lexunit_elt(elt, ignorekeys)
        lu.subCorpus = lu2.subCorpus
        
        return lu.subCorpus