Skip to content

Commit

Permalink
Release PHP beta3 version
Browse files Browse the repository at this point in the history
  • Loading branch information
lecoqlibre committed Jan 31, 2024
1 parent 58d66e8 commit c177f39
Show file tree
Hide file tree
Showing 7 changed files with 447 additions and 22 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ Ruby:
- Add Import method reading JSON and returning objects.
- Add `SEMANTIC_TYPE` constant to every semantic class.

Php:
- Add vocabulary thesaurus in tests.
- Add fetch method in `Connector`.
- Set default prefix value in `Connector` for dfc-f, dfc-m, dfc-pt and dfc-v.

### Fixed

Ruby:
Expand All @@ -21,6 +26,9 @@ Ruby:
- Enable loading of measures v1.0.2 (6ef17f7d4a19aebd9d89b544db115d36f7e6fe93).
- Improve SKOS Concept parsing ([PR #10](https://github.com/datafoodconsortium/connector-codegen/pull/10)).

Php:
- Fix missing `$` in variable name and missing `->` in `generateAdderBody`.

### Changed

Ruby:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ if ($other) {
[let parameter: Parameter = operation.getInputParameter()]
[let property: Property = operation.getProperty(aClass)]
[let map: String = property.getMapping()]
[if (parameter.type.isPrimitive())]this.addSemanticPropertyLiteral("[map/]", [parameter.name/]);[else]$this->addSemanticPropertyReference("[map/]", $[parameter.name/]);[/if][/let][/let][/let]
[if (parameter.type.isPrimitive())]$this->addSemanticPropertyLiteral("[map/]", $[parameter.name/]);[else]$this->addSemanticPropertyReference("[map/]", $[parameter.name/]);[/if][/let][/let][/let]
[/template]

[template public generateGetterBody(aClass: Class, operation: Operation)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.0.0-beta3] - 2024-01-31

### Added

- Support phone number and social media.
- Add logo to Agent.
- Add latitude, longitude and region to Address.
- Add hasFulfilmentStatus, hasOrderStatus and hasPaymentStatus to Order.
- Add `AsPlannedTransformation` loop.
- Add `Connector:fetch` and `IConnector:fetch`.
- Add default prefix value for dfc-f, dfc-m, dfc-pt and dfc-v.

### Changed

- Update Readme.

## [1.0.0-beta2] - 2023-09-19

### Fixed

- Allow [hyphen in prefix](https://github.com/sweetrdf/easyrdf/issues/32).

### Updated

- Update virtual-assembly/semantizer to version 1.0.0-beta2.

### Changed

- Update virtual-assembly/semantizer to version 1.0.0-beta2.
- Change prefix of all mapped objects from "dfc" to "dfc-b".
- Use "dfc-b" prefix in the `Connector` class.

Expand All @@ -31,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Initial release.

[unreleased]: https://github.com/datafoodconsortium/connector-php/compare/v1.0.0-beta1...HEAD
[unreleased]: https://github.com/datafoodconsortium/connector-php/compare/v1.0.0-beta3...HEAD
[1.0.0-beta3]: https://github.com/datafoodconsortium/connector-php/compare/v1.0.0-beta2...v1.0.0-beta3
[1.0.0-beta2]: https://github.com/datafoodconsortium/connector-php/compare/v1.0.0-beta1...v1.0.0-beta2
[1.0.0-beta1]: https://github.com/datafoodconsortium/connector-php/releases/tag/v1.0.0-beta1
72 changes: 57 additions & 15 deletions src/org/datafoodconsortium/connector/codegen/php/static/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,19 @@ You can then load our different SKOS taxonomies providing the corresponding JSON
$connector->import("/path/to/measures.json");
$connector->import("/path/to/facets.json");
$connector->import("/path/to/productTypes.json");
$connector->import("/path/to/vocabulary.json");
```

These taxonomies are accessible directly from the connector, like:
```PHP
// Example of a facet
$fruit = $connector->fetch("dfcf:Fruit");
$fruit = $connector->fetch("dfc-f:Fruit");

// Example of an measure
$kilogram = $connector->fetch("dfcm:Kilogram");
$kilogram = $connector->fetch("dfc-m:Kilogram");

// Example of a product type
$tomato = $connector->fetch("dfcpt:RoundTomato");
$tomato = $connector->fetch("dfc-pt:RoundTomato");
```

## Object creation
Expand All @@ -59,21 +60,21 @@ $allergenCharacteristic = new AllergenCharacteristic(
connector: $connector, // You have to pass a reference to the connector.
value: 1,
unit: $kilogram,
allergenDimension: $connector->fetch("dfcm:Peanuts");
allergenDimension: $connector->fetch("dfc-m:Peanuts");
);

$nutrientCharacteristic = new NutrientCharacteristic(
connector: $connector, // You have to pass a reference to the connector.
value: 10,
unit: $gram,
nutrientDimension: $connector->fetch("dfcm:Calcium")
nutrientDimension: $connector->fetch("dfc-m:Calcium")
);

$physicalCharacteristic = new PhysicalCharacteristic({
connector: $connector, // You have to pass a reference to the connector.
value: 100,
unit: $gram,
physicalDimension: $connector->fetch("dfcm:Weight")
physicalDimension: $connector->fetch("dfc-m:Weight")
});

$catalogItem = new CatalogItem({
Expand All @@ -85,21 +86,21 @@ $suppliedProduct = new SuppliedProduct({
connector: onnector, // You have to pass a reference to the connector.
semanticId: "http://myplatform.com/tomato",
description: "Awesome tomato",
productType: $connector->fetch("dfcpt:RoundTomato"),
productType: $connector->fetch("dfc-pt:RoundTomato"),
quantity: $quantity,
totalTheoreticalStock: 2.23,
alcoholPercentage: 0,
lifetime: "a week",
claims: [$connector->fetch("dfcf:NoAddedSugar")],
claims: [$connector->fetch("dfc-f:NoAddedSugar")],
usageOrStorageConditions: "free text",
allergenCharacteristics: [$allergenCharacteristic],
nutrientCharacteristics: [$nutrientCharacteristic],
physicalCharacteristics: [$physicalCharacteristic],
geographicalOrigin: $connector->fetch("dfcf:CentreValLoire"),
geographicalOrigin: $connector->fetch("dfc-f:CentreValLoire"),
catalogItems: [$catalogItem],
certifications: [$connector->fetch("dfcf:OrganicAB"), $connector->fetch("dfcf:OrganicEU")],
natureOrigin: [$connector->fetch("dfcf:PlantOrigin")],
partOrigin: [$connector->fetch("dfcf:Fruit")]
certifications: [$connector->fetch("dfc-f:OrganicAB"), $connector->fetch("dfc-f:OrganicEU")],
natureOrigin: [$connector->fetch("dfc-f:PlantOrigin")],
partOrigin: [$connector->fetch("dfc-f:Fruit")]
});
```

Expand All @@ -116,6 +117,9 @@ $suppliedProduct = new SuppliedProduct({
- `OrderLine`
- `Person`
- `PhysicalCharacteristic`
- `PlannedConsumptionFlow`
- `PlannedProductionFlow`
- `PlannedTransformation`
- `Price`
- `QuantitativeValue`
- `Quantity`
Expand All @@ -127,7 +131,7 @@ $suppliedProduct = new SuppliedProduct({
## Object accessors and mutators

### Read object properties (accessor)
You can read the properties of an objet using getter methods.
You can read the properties of an object using getter methods.

```PHP
$suppliedProduct->getDescription();
Expand All @@ -153,7 +157,7 @@ $suppliedProduct->setQuantity(new QuantitiveValue(connector: $connector, unit: $
You can also add a value to properties that are array:
```PHP
// Add a new certification to the product
$suppliedProduct->addCertification($connector->fetch("dfcf:AocFR"));
$suppliedProduct->addCertification($connector->fetch("dfc-f:AocFR"));
```

## Export objects
Expand Down Expand Up @@ -270,4 +274,42 @@ Connector::setFetchFunction(\Closure $fetch);
Connector::setFactory(IFactory $factory);
```

See the [Semantizer](https://github.com/assemblee-virtuelle/semantizer-php) documentation for more details.
See the [Semantizer](https://github.com/assemblee-virtuelle/semantizer-php) documentation for more details.

## Examples

### Planned transformation loop

```php
$connector = new Connector();
$connector->import("./test/thesaurus/measures.json");
$connector->import("./test/thesaurus/vocabulary.json");

$quantity = new Quantity(
connector: $connector,
unit: $connector->fetch("dfc-m:Kilogram"),
value: 1.0
);

$consumptionFlow = new PlannedConsumptionFlow(
connector: $connector,
semanticId: "http://example.org/consumptionFlow",
quantity: $quantity
);

$productionFlow = new PlannedProductionFlow(
connector: $connector,
semanticId: "http://example.org/productionFlow",
quantity: $quantity
);

$transformation = new PlannedTransformation(
connector: $connector,
semanticId: "http://example.org/transformation",
consumptionFlow: $consumptionFlow,
productionFlow: $productionFlow,
transformationType: $connector->fetch("dfc-v:combine")
);

echo $connector->export([$transformation, $consumptionFlow, $productionFlow]);
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace DataFoodConsortium\Connector;

use \VirtualAssembly\Semantizer\Semantizer;
use \VirtualAssembly\Semantizer\Semanticable;
use \VirtualAssembly\Semantizer\IFactory;
use \VirtualAssembly\Semantizer\SemanticObjectAnonymous;

class Connector implements IConnector {

Expand All @@ -15,6 +15,10 @@ public function __construct() {
$this->semantizer = new Semantizer();
$this->setFactory(new ConnectorFactory($this));
$this->setPrefix("dfc-b", "https://github.com/datafoodconsortium/ontology/releases/latest/download/DFC_BusinessOntology.owl#");
$this->setPrefix("dfc-f", "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/facets.rdf#");
$this->setPrefix("dfc-m", "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/measures.rdf#");
$this->setPrefix("dfc-pt", "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/productTypes.rdf#");
$this->setPrefix("dfc-v", "https://github.com/datafoodconsortium/taxonomies/releases/latest/download/vocabulary.rdf#");
$this->context = ["https://www.datafoodconsortium.org"];
}

Expand Down Expand Up @@ -55,6 +59,11 @@ public function export(Array $objects, Array $context = null): string {
return $this->getSemantizer()->export($objects, $context);
}

public function fetch(string $semanticId): Semanticable {
$expanded = $this->getSemantizer()->expand($semanticId); // allow to use prefixed id, like "dfc-m:Kilogram".
return $this->getSemantizer()->fetch($expanded);
}

/**
* The data can be supplied directly as string, by passing a file
* path, or by passing a URL.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
namespace DataFoodConsortium\Connector;

use \VirtualAssembly\Semantizer\Semantizer;
use \VirtualAssembly\Semantizer\Semanticable;

interface IConnector {

public function export(Array $objects): string;
public function fetch(string $semanticId): Semanticable;
public function import(string $data, string $baseUri): Array;
public function getSemantizer(): Semantizer;

Expand Down
Loading

0 comments on commit c177f39

Please sign in to comment.