Exemple #1
0
    def gettermmatcher(self):
        """returns the terminology matcher"""
        if self.is_terminology_project:
            if self.non_db_state.termmatcher is None:
                self.require_units()

            newmtime = self.get_mtime()
            if newmtime != self.non_db_state.termmatchermtime:
                self.non_db_state.termmatcher = match.terminologymatcher(self.stores.iterator())
                self.non_db_state.termmatchermtime = newmtime
        else:
            try:
                termfilename = "pootle-terminology." + self.project.localfiletype
                store = self.stores.get(name=termfilename)
                newmtime = store.get_mtime()
                if newmtime != self.non_db_state.termmatchermtime:
                    self.non_db_state.termmatcher = match.terminologymatcher(store)
                    self.non_db_state.termmatchermtime = newmtime
            except Store.DoesNotExist:
                try:
                    termproject = TranslationProject.objects.get(language=self.language_id, project__code="terminology")
                    self.non_db_state.termmatcher = termproject.gettermmatcher()
                    self.non_db_state.termmatchermtime = termproject.non_db_state.termmatchermtime
                except TranslationProject.DoesNotExist:
                    pass
        return self.non_db_state.termmatcher
Exemple #2
0
    def test_hyphen_mismatch(self):
        """Tests that we can match with some spacing mismatch"""
        csvfile = self.buildcsv(["pre-order"])
        matcher = match.terminologymatcher(csvfile)
        candidates = self.candidatestrings(matcher.matches("You can preorder"))
        assert candidates == ["preorder"]
        candidates = self.candidatestrings(matcher.matches("You can pre order"))
        assert candidates == ["pre order"]

        csvfile = self.buildcsv(["pre order"])
        matcher = match.terminologymatcher(csvfile)
        candidates = self.candidatestrings(matcher.matches("You can preorder"))
        assert candidates == ["preorder"]
        candidates = self.candidatestrings(matcher.matches("You can pre order"))
        assert candidates == ["pre order"]
Exemple #3
0
    def test_hyphen_mismatch(self):
        """Tests that we can match with some spacing mismatch"""
        csvfile = self.buildcsv(["pre-order"])
        matcher = match.terminologymatcher(csvfile)
        candidates = self.candidatestrings(matcher.matches("You can preorder"))
        assert candidates == ["preorder"]
        candidates = self.candidatestrings(matcher.matches("You can pre order"))
        assert candidates == ["pre order"]

        csvfile = self.buildcsv(["pre order"])
        matcher = match.terminologymatcher(csvfile)
        candidates = self.candidatestrings(matcher.matches("You can preorder"))
        assert candidates == ["preorder"]
        candidates = self.candidatestrings(matcher.matches("You can pre order"))
        assert candidates == ["pre order"]
Exemple #4
0
 def test_terminology(self):
     csvfile = self.buildcsv(["file", "computer", "directory"])
     matcher = match.terminologymatcher(csvfile)
     candidates = self.candidatestrings(
         matcher.matches("Copy the files from your computer"))
     candidates.sort()
     assert candidates == ["computer", "file"]
Exemple #5
0
 def test_space_mismatch(self):
     """Tests that we can match with some spacing mismatch"""
     csvfile = self.buildcsv(["down time"])
     matcher = match.terminologymatcher(csvfile)
     candidates = self.candidatestrings(
         matcher.matches("%d minutes downtime"))
     assert candidates == ["downtime"]
Exemple #6
0
 def test_past_tences(self):
     """Tests matching of some past tenses"""
     csvfile = self.buildcsv(["submit", "certify"])
     matcher = match.terminologymatcher(csvfile)
     candidates = self.candidatestrings(matcher.matches("The bug was submitted"))
     assert candidates == ["submit"]
     candidates = self.candidatestrings(matcher.matches("The site is certified"))
Exemple #7
0
    def gettermmatcher(self):
        """returns the terminology matcher"""
        terminology_stores = Store.objects.none()
        mtime = None
        if self.is_terminology_project:
            terminology_stores = self.stores.all()
            mtime = self.get_mtime()
        else:
            # Get global terminology first
            try:
                termproject = TranslationProject.objects.get(
                    language=self.language_id, project__code='terminology')
                mtime = termproject.get_mtime()
                terminology_stores = termproject.stores.all()
            except TranslationProject.DoesNotExist:
                pass

            local_terminology = self.stores.filter(
                name__startswith='pootle-terminology')
            for store in local_terminology.iterator():
                mtime = max(mtime, store.get_mtime())
            terminology_stores = terminology_stores | local_terminology
        if mtime is None:
            return
        if mtime != self.non_db_state.termmatchermtime:
            self.non_db_state.termmatcher = match.terminologymatcher(
                terminology_stores.iterator())
            self.non_db_state.termmatchermtime = mtime
        return self.non_db_state.termmatcher
Exemple #8
0
 def test_past_tences(self):
     """Tests matching of some past tenses"""
     csvfile = self.buildcsv(["submit", "certify"])
     matcher = match.terminologymatcher(csvfile)
     candidates = self.candidatestrings(matcher.matches("The bug was submitted"))
     assert candidates == ["submit"]
     candidates = self.candidatestrings(matcher.matches("The site is certified"))
Exemple #9
0
    def gettermmatcher(self):
        """returns the terminology matcher"""
        terminology_stores = Store.objects.none()
        mtime = None
        if self.is_terminology_project:
            terminology_stores = self.stores.all()
            mtime = self.get_mtime()
        else:
            # Get global terminology first
            try:
                termproject = TranslationProject.objects.get(language=self.language_id, project__code="terminology")
                mtime = termproject.get_mtime()
                terminology_stores = termproject.stores.all()
            except TranslationProject.DoesNotExist:
                pass

            local_terminology = self.stores.filter(name__startswith="pootle-terminology")
            for store in local_terminology.iterator():
                mtime = max(mtime, store.get_mtime())
            terminology_stores = terminology_stores | local_terminology
        if mtime is None:
            return
        if mtime != self.non_db_state.termmatchermtime:
            self.non_db_state.termmatcher = match.terminologymatcher(terminology_stores.iterator())
            self.non_db_state.termmatchermtime = mtime
        return self.non_db_state.termmatcher
Exemple #10
0
 def test_brackets(self):
     """Tests that brackets at the end of a term are ignored"""
     csvfile = self.buildcsv(["file (noun)", "ISP (Internet Service Provider)"])
     matcher = match.terminologymatcher(csvfile)
     candidates = self.candidatestrings(matcher.matches("Open File"))
     assert candidates == ["file"]
     candidates = self.candidatestrings(matcher.matches("Contact your ISP"))
     # we lowercase everything - that is why we get it back differently.
     # we don't change the target text, though
     assert candidates == ["isp"]
Exemple #11
0
 def test_brackets(self):
     """Tests that brackets at the end of a term are ignored"""
     csvfile = self.buildcsv(["file (noun)", "ISP (Internet Service Provider)"])
     matcher = match.terminologymatcher(csvfile)
     candidates = self.candidatestrings(matcher.matches("Open File"))
     assert candidates == ["file"]
     candidates = self.candidatestrings(matcher.matches("Contact your ISP"))
     # we lowercase everything - that is why we get it back differerntly.
     # we don't change the target text, though
     assert candidates == ["isp"]
    def _init_matcher(self):
        """
        Initialize the matcher to be used by the C{TerminologyPlaceable} parser.
        """
        if self.matcher in TerminologyPlaceable.matchers:
            TerminologyPlaceable.matchers.remove(self.matcher)

        self.store = TranslationStore()
        self.store.makeindex()
        self.matcher = terminologymatcher(self.store)
        TerminologyPlaceable.matchers.append(self.matcher)
Exemple #13
0
    def _init_matcher(self):
        """
        Initialize the matcher to be used by the C{TerminologyPlaceable} parser.
        """
        if self.matcher in TerminologyPlaceable.matchers:
            TerminologyPlaceable.matchers.remove(self.matcher)

        self.store = TranslationStore()
        self.store.makeindex()
        self.matcher = terminologymatcher(self.store)
        TerminologyPlaceable.matchers.append(self.matcher)
Exemple #14
0
    def load_files(self):
        if self.matcher in TerminologyPlaceable.matchers:
            TerminologyPlaceable.matchers.remove(self.matcher)

        self.stores = []
        for filename in self.config['files']:
            if not filename:
                continue
            if not os.path.isfile(filename):
                logging.debug('Not a file: "%s"' % (filename))
            self.stores.append(factory.getobject(filename))
        self.matcher = terminologymatcher(self.stores)
        TerminologyPlaceable.matchers.append(self.matcher)
Exemple #15
0
    def load_files(self):
        if self.matcher in TerminologyPlaceable.matchers:
            TerminologyPlaceable.matchers.remove(self.matcher)

        self.stores = []
        for filename in self.config['files']:
            if not filename:
                continue
            if not os.path.isfile(filename):
                logging.debug('Not a file: "%s"' % (filename))
            self.stores.append(factory.getobject(filename))
        self.matcher = terminologymatcher(self.stores)
        TerminologyPlaceable.matchers.append(self.matcher)
Exemple #16
0
    def _init_matcher(self):
        """
        Initialize the matcher to be used by the C{TerminologyPlaceable} parser.
        """
        if self.matcher in TerminologyPlaceable.matchers:
            TerminologyPlaceable.matchers.remove(self.matcher)

        from translate.storage.base import TranslationStore
        self.store = TranslationStore()
        self.store.makeindex()
        from translate.search.match import terminologymatcher
        self.matcher = terminologymatcher(self.store)
        TerminologyPlaceable.matchers.append(self.matcher)
Exemple #17
0
    def _init_matcher(self):
        """
        Initialize the matcher to be used by the C{TerminologyPlaceable} parser.
        """
        if self.matcher in TerminologyPlaceable.matchers:
            TerminologyPlaceable.matchers.remove(self.matcher)

        from translate.storage.base import TranslationStore

        self.store = TranslationStore()
        self.store.makeindex()
        from translate.search.match import terminologymatcher

        self.matcher = terminologymatcher(self.store)
        TerminologyPlaceable.matchers.append(self.matcher)
    def init_matcher(self, filename=''):
        """
        Initialize the matcher to be used by the C{TerminologyPlaceable} parser.
        """
        if self.matcher in TerminologyPlaceable.matchers:
            TerminologyPlaceable.matchers.remove(self.matcher)

        if os.path.isfile(filename):
            logging.debug('Loading terminology from %s' % (filename))
            self.store = factory.getobject(filename)
        else:
            logging.debug('Creating empty terminology store')
            self.store = TranslationStore()
        self.store.makeindex()
        self.matcher = terminologymatcher(self.store)
        TerminologyPlaceable.matchers.append(self.matcher)
Exemple #19
0
    def gettermmatcher(self):
        """Returns the terminology matcher."""
        terminology_stores = Store.objects.none()
        mtime = None

        if not self.is_terminology_project:
            # Get global terminology first
            try:
                termproject = TranslationProject.objects \
                        .get_terminology_project(self.language_id)
                mtime = termproject.get_mtime()
                terminology_stores = termproject.stores.all()
            except TranslationProject.DoesNotExist:
                pass

            local_terminology = self.stores.filter(
                    name__startswith='pootle-terminology')
            for store in local_terminology.iterator():
                if mtime is None:
                    mtime = store.get_mtime()
                else:
                    mtime = max(mtime, store.get_mtime())

            terminology_stores = terminology_stores | local_terminology

        if mtime is None:
            return

        if mtime != self.non_db_state.termmatchermtime:
            from translate.search import match
            self.non_db_state.termmatcher = match.terminologymatcher(
                    terminology_stores.iterator(),
            )
            self.non_db_state.termmatchermtime = mtime

        return self.non_db_state.termmatcher
Exemple #20
0
 def test_terminology(self):
     csvfile = self.buildcsv(["file", "computer", "directory"])
     matcher = match.terminologymatcher(csvfile)
     candidates = self.candidatestrings(matcher.matches("Copy the files from your computer"))
     candidates.sort()
     assert candidates == ["computer", "file"]
Exemple #21
0
 def test_space_mismatch(self):
     """Tests that we can match with some spacing mismatch"""
     csvfile = self.buildcsv(["down time"])
     matcher = match.terminologymatcher(csvfile)
     candidates = self.candidatestrings(matcher.matches("%d minutes downtime"))
     assert candidates == ["downtime"]
 def setup_method(self, method):
     self.term_po = pofile(BytesIO(self.TERMINOLOGY.encode("utf-8")))
     self.matcher = terminologymatcher(self.term_po)
     self.test_string = u"<b>Inpüt</b> file name thingy."
Exemple #23
0
 def setup_method(self, method):
     self.term_po = pofile(BytesIO(self.TERMINOLOGY.encode('utf-8')))
     self.matcher = terminologymatcher(self.term_po)
     self.test_string = u'<b>Inpüt</b> file name thingy.'
Exemple #24
0
 def setup_method(self, method):
     self.term_po = pofile(StringIO(self.TERMINOLOGY))
     self.matcher = terminologymatcher(self.term_po)
     self.test_string = u'<b>Inpüt</b> file name thingy.'