france是一个轻量级、灵活的数据管理系统
fracture的Python项目详细描述
概述
fracture是一个轻量级、灵活的数据管理系统。它允许 通过特征合成机制与数据交互,同时 还可以快速查询和访问信息 关于您正在探索的数据。
工作原理
首先创建断开项目。项目文件是所有 存储了元数据和查找表,允许您轻松搜索 以及查找更改。
france内置了一个文件搜索机制,但是您可以扩展 这也有你自己的搜索机制。例如,如果你有数据 在ftp上,或在源代码管理中,您希望将该数据添加到 项目而不必将它物理地放在磁盘上您可以这样做 通过实现fracture.scanprocess插件。
最后,可能最重要的是dataelement。这是一节课 你可以用它来表达数据的功能。而不是有一个 1:1数据元素类和数据类型之间的关系 类支持类合成。这允许一段数据 由多个类同时表示。
示例
本例使用dino_示例
数据,您可以从中下载
https://github.com/mikemalinowski/fracture
首先,我们创建一个断开项目。为此,我们必须指定 两条信息,第一条是我们想要保存的 项目文件,第二个是我们想要断开的位置 查找扫描和数据插件。
importosimportfractureproject=fracture.create(project_path=os.path.join(current_path,'_dino.fracture'),plugin_locations=[os.path.join(current_path,'plugins')])
这将返回一个fracture.project实例,然后我们可以开始交互 例如,我们可以用 正在查找数据:
# -- Tell the project where to look for dataproject.add_scan_location('/usr/my_data'))
最后,完成了这个项目,并且至少添加了一个搜索位置 可以启动搜索…
# -- Now we initiate a scan. This will cycle over all the# -- scan locations and scrape them for dataproject.scan()
扫描是运行所有扫描插件的过程,其中 总是至少有一个(文件刮刀),并用 关于找到的每一条数据的信息。过程很漂亮 快速且存储的数据量最小-主要是标识符 例如路径以及由任何数据元素组合定义的任何标记 它可以代表这些数据。
填充项目后,我们现在可以开始查询项目 数据
# -- Now we have scanned we can start to run queries over data# -- very quickly. We can search by tags, or use the special# -- * wildcardforiteminproject.find('*'):# -- By default we get string identifiers back from a find, as# -- this is incredibly quick. However, we can ask for the data# -- composite representation of the item. A data composite is# -- a composition of all the data plugins which can represent# -- this identifier.item=project.get(item)# -- Print the identifier, and the item (which also shows the# -- class composition)print(item.identifier())print('\t%s'%item)# -- We can start interacting with this data, calling# -- functionality will return a dictionary of all the# -- functionality exposed by all the data plugins representing# -- this itemfork,vinitem.functionality().items():print('\t\t%s = %s'%(k,v))
查询过程非常快速,即使对于相当大的数据集也是如此。在 上面的例子我们要求项目"获取"项目。这个过程 获取标识符并将所有相关的数据元素绑定在一起 可能代表数据。
当在
两个要素。例如,在dino_示例中
食肉动物的特征和食草动物的特征。那里
两者之间没有等级关系,但杂食动物需要
两者都有。通过使用类合成,我们避免了复杂的多重继承情况。
使用同样的机制,如果我们知道一条信息的定位器, 例如文件路径,我们可以直接获取合成类,而不必 运行查询,如下所示:
# -- We do not have to utilise the find method to get access to data,# -- and in fact we can get a Composite representation of data even# -- if that data is not within our scan location.data=project.get('/usr/my_data/my_file.txt')
对于完整的演示,请下载dino_示例并运行main.py
数据构成
如示例中所述,我们使用类组合将特征绑定在一起 来表示数据。这意味着我们可以有一些小的,自我包含的特征 不需要为它们设计严格的层次结构。
dataelement类中有三种主要的合成方法,具体来说:
- label:第一个返回正结果的调用被执行
- 强制标记:所有列表都是从所有组合中整理出来的,并且是唯一的
- 功能:所有Dictionaries组合成一个字典
- 图标:第一个返回肯定结果的调用被执行
给定dino_示例
文件,传递时为velociraptor.png文件
toproject.get('/usr/my_data/../velociraptor.png')
表示为
作为一个由以下特征组成的类:[食肉动物;文件;图像;]其中
trait可以公开自己的信息。
数据元素插件的实现如下:
importreimportfracture# -- All plugins must inherit from the fracture.DataElement class in order# -- to be dynamically picked up.classCarnivoreTrait(fracture.DataElement):# -- The data type is mandatory, and is your way of# -- denoting the name of this plugindata_type='carnivore'# -- These two lines are not at all required and are here# -- just to make performance better_split=re.compile('/|\.|,|-|:|_',re.I)_has_trait=re.compile('(carnivore|omnivore).*\.',re.I)# --------------------------------------------------------------------------# -- This method must be re-implemented, and its your oppotunity to# -- decide whether this plugin can viably represent the given data# -- identifier.# -- In this example we use a regex check, but it could be anything# -- you want. The key thing to remember is that this is called a lot,# -- so performance is worth keeping in mind.@classmethoddefcan_represent(cls,identifier):ifCarnivoreTrait._has_trait.search(identifier):returnTruereturnFalse# --------------------------------------------------------------------------# -- This is your way of exposing functionality in a common and consistent# -- way. If you know the data types you can of course call things directly# -- but this is a good catch up consistent way of exposing functionality# -- and is typically harnessed by user interfaces.deffunctionality(self):returndict(feed_meat=self.feed_meat,),)# --------------------------------------------------------------------------# -- This should return a 'nice name' for the identifierdeflabel(self):returnos.path.basename(self.identifier())# --------------------------------------------------------------------------# -- As fracture heavily utilises tags, this is your way of defining a# -- set of tags which are mandatory for anything with this traitdefmandatory_tags(self):return['carnivore','meat','hunter']# --------------------------------------------------------------------------# -- This is here just as a demonstration of a callable function which# -- which can be accessed on the traitdeffeed_meat(self):print('Would feed this creature some meat...')
通过将trait插件放置在您定义的插件位置中的任何位置 对于您的项目将立即使其可访问。
扫描过程
默认情况下,断开带有一个处理文件的内置扫描插件 扫描,所以这是一个很好的例子,当你想写你自己的-如果你 必须这样做。
此插件类型定义如何查找数据。如果数据是磁盘上的文件 例如上面例子中的那些,那么你的扫描插件可能做得更多 循环目录并生成文件路径。
或者,如果您正在缓存来自rest api的数据,则可能正在使用 扫描过程中的请求并反馈URL。
原点
此库是在 GDC2018(开发前向钻机、工具和 管道),可以在这里进行更详细的探讨: https://www.gdcvault.com/play/1025427/a-practical-approach-to-developing
接下来的第55张幻灯片探讨了这个概念。同时也进行了详细的探讨 在此网页上: https://www.twisted.space/blog/insight本地化资产管理
协作
我总是乐于合作,所以如果你发现了虫子就告诉我,或者 你想贡献或参与只是呼喊!
兼容性
launchpad已经在windows和ubuntu上的python 2.7和python 3.7下进行了测试。