Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 45 lines (32 sloc) 1.376 kb
311ef3f Nicolas R Dufour Unify the app
authored
1
e14a191 Nicolas R Dufour Bad copy-paste...
authored
2 % This file is part of urdf released under the MIT license.
311ef3f Nicolas R Dufour Unify the app
authored
3 % See the LICENSE file for more information.
4
5 -module(urdf_t2n).
6 -author("Nicolas R Dufour <nicolas.dufour@nemoworld.info>").
7
8 -export([convert/1]).
9
10 -include("triples.hrl").
11
12 convert(Triples) ->
0f56886 Nicolas R Dufour Extract factorize in its own module and make sure we use #triple record ...
authored
13 Entities = urdf_triple:factorize(Triples),
bcb2eac Nicolas R Dufour Finalize the conversion from triples to ntriples.
authored
14
0f56886 Nicolas R Dufour Extract factorize in its own module and make sure we use #triple record ...
authored
15 ConvertValue = fun(Triple, {ItemId, Acc}) ->
16
17 Key = Triple#triple.property,
18 Value = Triple#triple.object,
19 Type = Triple#triple.type,
bcb2eac Nicolas R Dufour Finalize the conversion from triples to ntriples.
authored
20
21 WrappedValue = case Type of
22 resource ->
23 case Value of
24 << "_:", _Rest/binary >> -> Value;
e3bc670 Nicolas R Dufour Using iolist_to_binary instead of list_to_binary.
authored
25 _ -> iolist_to_binary([<<"<">>, Value, <<">">>])
bcb2eac Nicolas R Dufour Finalize the conversion from triples to ntriples.
authored
26 end;
e3bc670 Nicolas R Dufour Using iolist_to_binary instead of list_to_binary.
authored
27 _ -> iolist_to_binary([<<"\"">>, Value, <<"\"">>])
bcb2eac Nicolas R Dufour Finalize the conversion from triples to ntriples.
authored
28 end,
29
e3bc670 Nicolas R Dufour Using iolist_to_binary instead of list_to_binary.
authored
30 NewValue = iolist_to_binary([ItemId, <<" <">>, Key, <<"> ">>, WrappedValue, <<".\n">>]),
e9c7c00 Nicolas R Dufour Change the code to really convert to N-Triples format.
authored
31 {ItemId, << Acc/binary, NewValue/binary >>}
bcb2eac Nicolas R Dufour Finalize the conversion from triples to ntriples.
authored
32 end,
33
34 ConvertEntity = fun(ItemId, Values, Acc) ->
e9c7c00 Nicolas R Dufour Change the code to really convert to N-Triples format.
authored
35 WrappedItemId = case ItemId of
36 << "_:", _Rest/binary >> -> ItemId;
e3bc670 Nicolas R Dufour Using iolist_to_binary instead of list_to_binary.
authored
37 _ -> iolist_to_binary([<<"<">>, ItemId, <<">">>])
e9c7c00 Nicolas R Dufour Change the code to really convert to N-Triples format.
authored
38 end,
39
40 {_, DisplayedValues} = lists:foldl(ConvertValue, {WrappedItemId, <<"">>}, Values),
e3bc670 Nicolas R Dufour Using iolist_to_binary instead of list_to_binary.
authored
41 Acc ++ [iolist_to_binary([DisplayedValues, <<"\n">>])]
bcb2eac Nicolas R Dufour Finalize the conversion from triples to ntriples.
authored
42 end,
43
e3bc670 Nicolas R Dufour Using iolist_to_binary instead of list_to_binary.
authored
44 iolist_to_binary(dict:fold(ConvertEntity, [], Entities)).
Something went wrong with that request. Please try again.