Thanks Beverly

 

The inference examples you pointed out are very helpful. => 
https://developer.marklogic.com/features/semantics/inference-examples

 

Although, unless I’m missing something, in my case, I don’t see a need for the 
inference query.

 

For now, I’m just using the triple to capture data field mappings. Using a 
triple for this seems like a more flexible/more efficient approach than adding 
a generalized field name to every document.

 

I’m a “Combination Query” newbie but I believe the idea is to run a SPARQL 
query and then feed the results to a cts:search() query.

 

Here’s the code that I am currently using. It is in 3 parts. The first 2 parts 
are SPARQL Updates the last is XQuery.

 

## 1. Create Field Mapping Graph

CREATE GRAPH <http://example.com/field-mappings-1> ;

 

 

## 2. Insert Field Mapping triples into Graph

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

PREFIX dom: <http://example.com/products/>

PREFIX owl: <http://www.w3.org/2002/07/owl#>

 

INSERT DATA

{

  GRAPH <http://example.com/field-mappings-1>

  {

    dom:phone owl:equivalentProperty "CUPHONE" .

    dom:phone owl:equivalentProperty "Telephone" .

    dom:phone owl:equivalentProperty "TEL-TYPE-1" .

  }

}

 

(: 3. Combination Query to Query Phone Numbers :)

 

import module namespace sem = "http://marklogic.com/semantics"; at 
"/MarkLogic/semantics.xqy";

 

declare variable $NS := "http://example.com/aptp";;

 

let $results :=

  sem:query-results-serialize(sem:sparql('

    PREFIX dom: <http://example.com/products/>

    PREFIX owl: <http://www.w3.org/2002/07/owl#>

    

    SELECT ?fields

    FROM <http://example.com/field-mappings-1>

    WHERE

    {

      dom:phone owl:equivalentProperty ?fields .

    }',

    (), (), ()

  ))

 

let $fields := 
$results/*:results/*:result/*:binding[@name="fields"]/*:literal/text()

 

let $source := "SystemB"

let $phoneNumber := "11-301-555-*"

 

(: Use the SPARQL results to generate an OR Query :)

let $elementValueQueryOrQuery :=

  cts:or-query((

    for $field in $fields

      return

        cts:element-value-query(fn:QName($NS, $field), $phoneNumber)

  ))

 

(: Inserts the OR Query into the following AND Query :)

let $query := cts:and-query((

                  cts:collection-query(("party")),

                  cts:element-value-query(fn:QName($NS, "Source"), $source),

                  $elementValueQueryOrQuery

                ))

 

let $results := cts:search(fn:doc(), $query)

 

return

(

  fn:count($results),

  $results

)

 

 

 

From: [email protected] 
[mailto:[email protected]] On Behalf Of Beverly Jamison
Sent: Sunday, April 10, 2016 8:23 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] What SPARQL Query to use to retrieve phone 
numbers from documents that have various phone field names?

 

Hi Gary,

 

Would you be able to use owl:equivalentProperty via a ruleset in your 
environment?

 

If so, you could add

 

fibo:FullPhoneNumber owl:equivalentProperty fibo:CUPHONE .

fibo:FullPhoneNumber owl:equivalentProperty fibo:Telephone .

fibo:FullPhoneNumber owl:equivalentProeprty fibo:TEL-TYPE-1 .

 

to your INSERT DATA statement and then query for just one of the properties.

 

Examples 3 and 4 in 
https://developer.marklogic.com/features/semantics/inference-examples have the 
full syntax for doing this with owl:equivalentProperty. If you don't have an 
environment that would allow that, there should be a way to reproduce the 
reasoning in RDF / sparql only as well.

 

Best Regards,

Beverly Jamison

 

 

On Sat, Apr 9, 2016 at 2:28 PM, Gary Russo <[email protected]> wrote:

What Combination SPARQL Query should be used to query phone numbers from
documents where field names vary?

I'd like to used triples to do the field mapping.

The following triples are may be used to map the various phone number fields
to dom:phone.

PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns# 
<http://www.w3.org/1999/02/22-rdf-syntax-ns> >
PREFIX fibo: <http://example.com/fibo/>
PREFIX dom:  <http://example.com/products/>

INSERT DATA
{
  GRAPH <http://example.com/field-mappings-1>
  {
    fibo:FullPhoneNumber rdf:type dom:phone .
    fibo:CUPHONE         rdf:type dom:phone .
    fibo:Telephone       rdf:type dom:phone .
    fibo:TEL-TYPE-1      rdf:type dom:phone .
  }
}


Here are the 3 XML documents that use different field names for a telephone
number.

/party/1001.xml

<fibo:Party xmlns:aptp="http://example.com/fibo";>
    <fibo:Source>SystemA</fibo:Source>
    <fibo:Customer>Xerox</fibo:Customer>
    <fibo:Created>2016-02-26</fibo:Created>
    <fibo:LastModified>2016-02-26</fibo:LastModified>
    <fibo:Person>
        <fibo:FullName>Grace Hopper</fibo:FullName>
        <fibo:FullPhoneNumber>11-301-555-1212</fibo:FullPhoneNumber>
        <fibo:city>Sunnyvale</fibo:city>
        <fibo:state>California</fibo:state>
    </fibo:Person>
</fibo:Party>


/party/1002.xml

<fibo:Party xmlns:aptp="http://example.com/fibo";>
    <fibo:Source>SystemB</fibo:Source>
    <fibo:Customer>Apple</fibo:Customer>
    <fibo:Created>2016-02-26</fibo:Created>
    <fibo:LastModified>2016-02-26</fibo:LastModified>
    <fibo:Person>
        <fibo:FullName>Marissa Mayer</fibo:FullName>
        <fibo:CUPHONE>11-301-555-4444</fibo:CUPHONE>
        <fibo:city>Los Angeles</fibo:city>
        <fibo:state>California</fibo:state>
    </fibo:Person>
</fibo:Party>


/party/1003.xml

<fibo:Party xmlns:aptp="http://example.com/fibo";>
    <fibo:Source>SystemC</fibo:Source>
    <fibo:Customer>Microsoft</fibo:Customer>
    <fibo:Created>2016-02-26</fibo:Created>
    <fibo:LastModified>2016-02-26</fibo:LastModified>
    <fibo:Person>
        <fibo:FullName>Sheryl Sandberg</fibo:FullName>
        <fibo:Telephone type="1">301-555-1212</fibo:Telephone>
        <fibo:city>Redmond</fibo:city>
        <fibo:state>Washington</fibo:state>
    </fibo:Person>
</fibo:Party>


What query should be used to retrieve the phone numbers for all 3 documents
using the field mapping triples noted above?

Any thoughts/advice on this is much appreciated.

Regards,
Gary Russo



_______________________________________________
General mailing list
[email protected]
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general

 

_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to