You can post-process the result of this step using smf:trim to get rid
of the spaces.
?rawDay tops:split ("Monday and Friday, Tuesday, Wednesday" ",") .
LET (?day := smf:trim(?rawDay)) .
...
I would prefer to leave such concerns separated unless you have cases
where the above solution would not work.
Regards,
Holger
On May 21, 2009, at 9:58 AM, Smith, Tim wrote:
>
> That's great news! It will be nice to eliminate a custom function.
>
> With regards to "trim or not to trim", how does this parse?
>
> ?day tops:split("Monday and Friday, Tuesday, Wednesday" ",")
>
> What happens to the spaces? This example will not return empty
> strings. I've found that most string split algorithms in java will
> include the space on the frontend, i.e. the returned strings will
> be: (minus the quotes, of course...)
>
> "Monday and Friday"
> " Tuesday"
> " Wednesday"
>
> In 99% of the cases I need to remove the leading space thus my use
> of trim within :split.
>
> Thanks for adding the split function!
>
> Tim
>
>> -----Original Message-----
>> From: [email protected] [mailto:topbraid-
>> [email protected]] On Behalf Of Holger Knublauch
>> Sent: Thursday, May 21, 2009 11:29 AM
>> To: [email protected]
>> Subject: [tbc-users] Re: How to extract multiple values from a space-
>> delimited string?
>>
>>
>> Good suggestion. I have just added tops:split for the next release.
>> Example:
>>
>> ?str tops:split ("AAA BB CC " " ") .
>>
>> will bind ?str with
>> AAA
>> BB
>> CC
>>
>> The second argument is a regular expression. Since empty strings will
>> be ignored, no trim is needed IMHO.
>>
>> Holger
>>
>>
>> On May 21, 2009, at 6:24 AM, Smith, Tim wrote:
>>
>>>
>>> Hi Phil,
>>>
>>> I also did not see a function that will split a string based on a
>>> delimiter in the latest version. I need to split strings based on
>>> arbitrary delimiters all the time so I wrote a split string function
>>> in java and made it a property function to use in CONSTRUCT queries.
>>>
>>> In addition to splitting strings it also takes a parameter that when
>>> TRUE, automatically trims the strings of leading/trailer whitespace
>>> before returning them. This is very useful since you would likely
>>> need to trim each one before using it to generate a URI, etc.
>>>
>>> It would be a very helpful function to have in the base product.
>>>
>>> Tim
>>>
>>>
>>>> -----Original Message-----
>>>> From: [email protected] [mailto:topbraid-
>>>> [email protected]] On Behalf Of
>> [email protected]
>>>> Sent: Thursday, May 21, 2009 8:05 AM
>>>> To: TopBraid Composer Users
>>>> Subject: [tbc-users] Re: How to extract multiple values from a
>> space-
>>>> delimited string?
>>>>
>>>>
>>>> Scott -
>>>>
>>>> I know how to use the string function to separate a SINGLE string
>>>> out,
>>>> but how do I get them ALL parsed out given that the number of
>>>> individual elements is unknown (i.e. one drug might be related to 3
>>>> others and another drug might have 17 related drugs)?
>>>>
>>>> On May 21, 8:01 am, Scott Henninger <[email protected]>
>>>> wrote:
>>>>> Phil, the "BBB CCC..." string will need to be parsed an
>> individually
>>>>> turned into URIs. See the String Functions in the SPARQLMotion
>>>>> Functions Reference in the Help files.
>>>>>
>>>>> -- Scott
>>>>>
>>>>> On May 21, 7:56 am, [email protected] wrote:
>>>>>
>>>>>
>>>>>
>>>>>> I have a sparql motion script that iterates over a series of xml
>>>> files
>>>>>> (1 drug per file), converts the XML into RDF, and creates
>> instances
>>>> of
>>>>>> the classes/properties from an ontology. One of the elements
>>>> within
>>>>>> the xml is a series space-separated values that I need to parse
>>>> into
>>>>>> individual triples of a given property. Here is a simple example:
>>>>>
>>>>>> <?xml version="1.0" encoding="UTF-8" ?>
>>>>>> <Drug ID="AAA">
>>>>>> <DrugName>
>>>>>> <![CDATA[ dummy ]]>
>>>>>> </DrugName>
>>>>>> <RelatedDrug>
>>>>>> <![CDATA[ BBB CCC DDD EEE FFF GGG ]]>
>>>>>> </RelatedDrug>
>>>>>> </Drug>
>>>>>
>>>>>> I need to generate triples like the following:
>>>>>
>>>>>> :AAA a :Drug .
>>>>>> :AAA :hasName "dummy" .
>>>>>> :AAA :isRelatedTo :BBB .
>>>>>> :AAA :isRelatedTo :CCC .
>>>>>> :AAA :isRelatedTo :DDD .
>>>>>> :AAA :isRelatedTo :EEE .
>>>>>> :AAA :isRelatedTo :FFF .
>>>>>> :AAA :isRelatedTo :GGG .
>>>>>
>>>>>> The number of related drugs will differ from drug to drug (i.e.
>>>> file
>>>>>> to file). The files are being processed via an IterateOverSelect
>>>>>> module where the body of that module is a series of construct
>>>> modules
>>>>>> that produce the individual triples you see above. However, what
>> I
>>>> am
>>>>>> getting now is:
>>>>>
>>>>>> :AAA a :Drug .
>>>>>> :AAA :hasName "dummy" .
>>>>>> :AAA :isRelatedTo :BBB_CCC_DDD_EEE_FFF_GGG .
>>>>>
>>>>>> How can I split that last element up into individual triples?
>>>>>
>>>>>> Phil- Hide quoted text -
>>>>>
>>>>> - Show quoted text -
>>>>
>>>
>>>>
>>
>>
>>
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TopBraid Composer Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/topbraid-composer-users?hl=en
-~----------~----~----~----~------~----~------~--~---