コード例 #1
0
ファイル: album.py プロジェクト: jacebrowning/enharmony
    def _split(text):  # TODO: make this logic common
        """Split an album title into parts.

        @param text: string to split into parts
        @return: name, kind, featuring
        """
        kind = featuring = None
        # Strip featured artists
        match = re.search(RE_FEATURING, text, re.IGNORECASE | re.VERBOSE)
        if match:
            featuring = match.group(1)
            logging.debug("match found: {0}".format(featuring))
            text = text.replace(
                match.group(0),
                '').strip()  # remove the match from the remaining text
        # Strip song kinds
        for kind in settings.KINDS:
            re_kind = RE_KIND.replace('<kind>', kind)
            match = re.search(re_kind, text, re.IGNORECASE | re.VERBOSE)
            if match:
                logging.debug("match found: {0}".format(kind))
                text = text.replace(
                    match.group(0),
                    '').strip()  # remove the match from the remaining text
                break
        else:
            kind = None
        # Return parts
        return TextTitle.fromstring(text), TextEnum.fromstring(
            kind), TextList.fromstring(featuring)
コード例 #2
0
 def test_parse_list_with_and(self):
     """Verify a 3-item text list is parsed."""
     lst = TextList("This, That, and  the Other ")
     self.assertEqual(
         (TextName("This"), TextName("That"), TextName("the Other")),
         lst.items)
     self.assertEqual("This, That, the Other", str(lst))
コード例 #3
0
ファイル: album.py プロジェクト: jacebrowning/enharmony
    def _split(text):  # TODO: make this logic common
        """Split an album title into parts.

        @param text: string to split into parts
        @return: name, kind, featuring
        """
        kind = featuring = None
        # Strip featured artists
        match = re.search(RE_FEATURING, text, re.IGNORECASE | re.VERBOSE)
        if match:
            featuring = match.group(1)
            logging.debug("match found: {0}".format(featuring))
            text = text.replace(match.group(0), '').strip()  # remove the match from the remaining text
        # Strip song kinds
        for kind in settings.KINDS:
            re_kind = RE_KIND.replace('<kind>', kind)
            match = re.search(re_kind, text, re.IGNORECASE | re.VERBOSE)
            if match:
                logging.debug("match found: {0}".format(kind))
                text = text.replace(match.group(0), '').strip()  # remove the match from the remaining text
                break
        else:
            kind = None
        # Return parts
        return TextTitle.fromstring(text), TextEnum.fromstring(kind), TextList.fromstring(featuring)
コード例 #4
0
ファイル: test_album.py プロジェクト: jacebrowning/enharmony
 def test_ep(self):
     """Verify an EP can be parsed."""
     album = Album("Tracks (feat. The Artist) [EP]")
     self.assertEqual(TextTitle("Tracks"), album.name)
     self.assertEqual(TextEnum("EP"), album.kind)
     self.assertEqual(TextList("The Artist"), album.featuring)
     self.assertEqual("Tracks [EP]", str(album))
コード例 #5
0
 def test_similar_equal(self):
     """Verify two equal text lists are similar."""
     similarity = TextList("This + That") % TextList("This + That")
     self.assertTrue(similarity)
     self.assertEqual(1.0, similarity)
コード例 #6
0
 def test_similar_unequal(self):
     """Verify two different text lists are not similar."""
     similarity = TextList("This, That, and  the Other ") % TextList(
         "This Other Thing & One")
     self.assertFalse(similarity)
     self.assertGreater(0.31, similarity)
コード例 #7
0
 def test_parse_pair(self):
     """Verify a 2-item text list is parsed."""
     lst = TextList(" Something &  This Thing")
     self.assertEqual((TextName("Something"), TextName("This Thing")),
                      lst.items)
     self.assertEqual("Something, This Thing", str(lst))
コード例 #8
0
 def test_similar_close(self):
     """Verify two close text lists are similar."""
     similarity = TextList("This, That, and  the Other ") % TextList(
         "That, This &  the Other ")
     self.assertTrue(similarity)
     self.assertLess(0.99, similarity)