Commit 82a3c424 authored by Clément Schreiner's avatar Clément Schreiner
Browse files

Implement the 'similar packages' search in a new importer plugin: SemanticPlugin.

parent 17c9bd91
# -*- coding: utf-8 -*-
#
# utils.py — Debexpo utility functions
# semantic.py — Semantic metadata functions
#
# This file is part of debexpo - https://alioth.debian.org/projects/debexpo/
#
......@@ -36,7 +36,7 @@ import xapian
from apt.cache import Cache
class SemanticPackage(object):
class SemanticData(object):
def __init__(self, packages, descriptions):
self.db = xapian.Database("/var/lib/apt-xapian-index/index")
self.cache = Cache()
......
......@@ -41,9 +41,6 @@ from sqlalchemy import orm
from debexpo.model import meta, OrmObject
from debexpo.model.packages import Package
from debexpo.lib.semantic import SemanticPackage
t_package_versions = sa.Table('package_versions', meta.metadata,
sa.Column('id', sa.types.Integer, primary_key=True),
sa.Column('package_id', sa.types.Integer, sa.ForeignKey('packages.id')),
......@@ -68,18 +65,6 @@ class PackageVersion(OrmObject):
from debexpo.model.binary_packages import BinaryPackage
return meta.session.query(BinaryPackage).filter_by(package_version_id=self.id).all()
def get_similar_packages(self):
package = meta.session.query(Package).filter_by(id=self.id)
binary_packages = self.get_binary_packages()
packages = [b.name for b in binary_packages]
descriptions = [b.get_description() for b in binary_packages]
sp = SemanticPackage(packages, descriptions)
return sp.iter_similar_packages()
orm.mapper(PackageVersion, t_package_versions, properties={
'package' : orm.relation(Package, backref='package_versions')
})
# -*- coding: utf-8 -*-
#
# semantic.py — semantic plugin
#
# This file is part of debexpo - https://alioth.debian.org/projects/debexpo/
#
# Copyright © 2008 Jonny Lamb <jonny@debian.org>
# Copyright © 2012 Nicolas Dandrimont <Nicolas.Dandrimont@crans.org>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
"""
Holds the semantic plugin.
"""
__author__ = 'Clément Schreiner'
__copyright = 'Copyright © 2012 Clément Schreiner'
__license__ = 'MIT'
import logging
from debexpo.plugins import BasePlugin
from debexpo.model.plugin_results import PluginResult, plugin_result_mapper
from debexpo.lib.semantic import SemanticData
from sqlalchemy import orm
log = logging.getLogger(__name__)
class SemanticResult(PluginResult):
pass
orm.mapper(SemanticResult, inherits=plugin_result_mapper,
polymorphic_identity = 'semantic')
class SemanticPlugin(BasePlugin):
result_model = SemanticResult
def test_similar_packages(self):
binary_packages = self.package_version.get_binary_packages()
packages = [b.name for b in binary_packages]
descriptions = [b.get_description() for b in binary_packages]
sd = SemanticData(packages, descriptions)
_id = 0
for p in sd.iter_similar_packages():
self._add_data(id=_id, **p)
_id += 1
plugin = SemanticPlugin
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment