conjecto/nemrod 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

conjecto/nemrod

Composer 安装命令:

composer require conjecto/nemrod

包简介

Nemrod is a framework providing an abstraction layer for handling (consuming and producing) RDF in a Symfony2 project

README 文档

README

What is Nemrod?

Nemrod is a framework providing an abstraction layer for handling (consuming and producing) RDF in a Symfony2 project, in the same way Symfony users are using Doctrine. The framework provides five main components:

  • a resource manager (similar to Doctrine's resource manager)
  • a SPARQL query builder allowing to interact directly with your sparql endpoint(s)
  • a form extension allowing to build forms to create or update data
  • a json-ld serializer allowing to produce framed json-ld representation of RDF
  • Optionally, a set of services can be set up that populates and update an Elasticsearch server wrt triple store content.

Nemrod mainly relies on

Demo project

A quick way to test Nemrod Abilities before installing it into your project is to try our demo project

Requirements

Installation

Nemrod can be installed using composer :

composer require conjecto/nemrod easyrdf/easyrdf:@dev conjecto/json-ld:@dev

you can also add dependency directly in your composer.json file:

"conjecto/nemrod": "master"
"easyrdf/easyrdf": "@dev"
"conjecto/json-ld": "@dev"

Then you need to add one (or two) bundle(s) to the AppKernel.php:

class AppKernel extends Kernel
{
	public function registerBundles()
	{
    	$bundles = array(
		    ...
		    new Conjecto\Nemrod\Bundle\NemrodBundle\NemrodBundle(),
		    new Conjecto\Nemrod\Bundle\ElasticaBundle\ElasticaBundle(),
		    ...
		);
	}
}

The first bundle is the main framework bundle, the second should be enabled only if you wish to use an ElasticSearch server.

A little bit of configuration is necessary to let Nemrod know one thing or two about your environment:

nemrod:
  endpoints:
    my_endpoint: "http://www.foo.org/sparql"
	another_endpoint: "http://www.bar.net/sparql"
  default_endpoint: my_endpoint
  namespaces:
    rdfs: "http://www.w3.org/2000/01/rdf-schema#"
    foaf: "http://xmlns.com/foaf/0.1/"
    #add the namespaces you need
	mycompany: "http://www.example.org/mycompany"

At this point, Nemrod knows enough to access to your data. Use the 'rm' service's findAll() (which is an alias for 'nemrod.resource_manager.my_endpoint'):

<?php

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

class ProductsController extends Controller
{
	/**
 	 * @Route("/all/", name="product.index")
 	 * @Template("ProductsBundle:index.html.twig")
 	 */
	public function indexAction()
	{
		$products = $this->container->get('rm')->getRepository('mycompany:Product')->findAll();
		...
		return array("products" => $products);
	}
}

Alternatively, you can refine the set of data you want to get using the findBy() method:

	/**
 	 * @Route("/category/{category}", name="product.category")
 	 * @Template("ProductsBundle:index.html.twig")
 	 */
	public function categoryAction($category)
	{
		$products = $this->container->get('rm')
			->getRepository('mycompany:Product')
			->findBy(array('mycompany:category' => $category));
		...
		return array("products" => $products);
	}

You can then display your data using twig:

<ul>
	{% for product in products %}
    	<li class="list-group-item">{{ product['rdfs:label'].value }}</li>
  	{% endfor %}
</ul>

Another possibility is to ask for a specific resource using its uri:

	/**
 	 * @Route("/view/{uri}", name="product.view")
 	 * @Template("ProductsBundle:view.html.twig")
 	 */
	public function viewAction($uri)
	{
		$product = $this->container->get('rm')
			->getRepository('mycompany:Product')
			->find($uri);
		...
		return array("product" => $product);
	}

You can also use the paramConverter to get the resource directly. In this example, the product variable is automatically instanciated.

    /**
 	 * @Route("/view/{uri}", name="product.view")
 	 * @ParamConverter("product", class="mycompany:Product")
 	 * @Template("ProductsBundle:view.html.twig")
 	 */
	public function viewAction($product)
	{
		return array("product" => $product);
	}

If you need to encapsulate specific logic over your data, you can overload the default resource abstraction class. Overloading class must be defined in a RdfResource directory of your bundle directory:

+-- ProductBundle
|   +-- Controller
|   +-- DependencyInjection
|   +-- Resources
|   +-- RdfResource
|		+-- Product

and must extend Conjecto\Nemrod\Resource (which is the default abstraction class):

<?php

namespace MyCompany\ProductBundle\RdfResource;

use Conjecto\Nemrod\Resource as BaseResource;
use Conjecto\Nemrod\ResourceManager\Annotation\Resource;

/**
 * Class Product
 * @Resource(types={"mycompany:Product"}, uriPattern = "mycompany:product:")
 */
class Product extends BaseResource
{

}

the @Resource annotation allows to map your class and RDF types, so you can get an instance of this class when asking for object with the given types:

$product = $this->container->get('rm')->getRepository('mycompany:Product')->find($uri);

will fill $products with an array of MyCompany\ProductBundle\RdfResource\Product objects.

An URI pattern can also be provided with uriPattern. It will be used to set an URI for a new resource. For now, the specified pattern is just used as a prefix

Documentation

Contributing

  • Feel free to install and test the framework. We'd love to have some feedback about it.
  • A lot of tests has to be written. We are currently putting effort on that point. Any help would be appreciated.

Licensing

The Nemrod framework is licensed under the BSD-3-Clause license.

conjecto/nemrod 适用场景与选型建议

conjecto/nemrod 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 706 次下载、GitHub Stars 达 23, 最近一次更新时间为 2015 年 03 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「jsonld」 「rdfa」 「RDF」 「Semantic Web」 「Turtle」 「sparql」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 conjecto/nemrod 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 conjecto/nemrod 我们能提供哪些服务?
定制开发 / 二次开发

基于 conjecto/nemrod 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 706
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 23
  • 点击次数: 28
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 23
  • Watchers: 11
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-03-25