Thanks Danny, It is working perfectly for me and performance is also not issue.

 

Regards.

 

From: [email protected] 
[mailto:[email protected]] On Behalf Of Danny Sokolsky
Sent: Tuesday, July 06, 2010 8:38 PM
To: General Mark Logic Developer Discussion
Subject: Re: [MarkLogic Dev General] fuzzy node comparison logic

 

How about if you compare *each* of the child nodes of $x to *all* of the child 
nodes of $y, then if more than ½ of them are the same then call it true.  Note 
that this is a lot different from a deep-equal though, as you have thrown out 
all notion of ordering.  I think if you can come up with exactly what you want 
to compare, you should be able to code it up.  Something like:

 

xquery version "1.0-ml";

let $x := <List xmlns="http://www.mynamespace.com/report/1";>

       <item>

              <term1>a b c</term1> 

              <term2>key1</term2> 

       </item>

       <item>

              <term1>d e f</term1> 

              <term2>key2</term2> 

       </item>

       <item>

              <term1>g h i.</term1> 

              <term2>key3</term2> 

       </item>

       <item>

              <term1>j k l</term1> 

              <term2>key4</term2> 

       </item>

       <item>

              <term1>m n o</term1> 

              <term2>key5</term2> 

       </item>

</List>

let $y :=

<List xmlns="http://www.mynamespace.com/report/1";>

       <item>

              <term1>a b c</term1> 

              <term2>key1</term2> 

       </item>

       <item>

              <term1>d e f</term1> 

              <term2>key2</term2> 

       </item>

       <item>

              <term1>g h i.</term1> 

              <term2>key6</term2> 

       </item>

       <item>

              <term1>j k l</term1> 

              <term2>key4</term2> 

       </item>

</List>

let $nodes1 := $x/node()

let $nodes2 := $y/node()

let $count := fn:count($nodes1)

let $equalnodes :=

  for $node in $nodes1

  return

   if ($node = $nodes2) then $node else ()

return  

if ((fn:count($equalnodes) div $count) ge .5) then fn:true() else fn:false()

 

-Danny

 

From: [email protected] 
[mailto:[email protected]] On Behalf Of Joshi, Utsav 
(LNG-CON)
Sent: Tuesday, July 06, 2010 1:23 PM
To: General Mark Logic Developer Discussion
Subject: Re: [MarkLogic Dev General] fuzzy node comparison logic

 

Thanks Danny. 

But this logic will not work if my nodes changed as below. 

 

If check node by node using 2 loops it'll be very slow (node $x and node $y are 
part of another big node sequence).

 

xquery version "1.0-ml";

let $x := <List xmlns="http://www.mynamespace.com/report/1";>

       <item>

              <term1>a b c</term1> 

              <term2>key1</term2> 

       </item>

       <item>

              <term1>d e f</term1> 

              <term2>key2</term2> 

       </item>

       <item>

              <term1>g h i.</term1> 

              <term2>key3</term2> 

       </item>

       <item>

              <term1>j k l</term1> 

              <term2>key4</term2> 

       </item>

       <item>

              <term1>m n o</term1> 

              <term2>key5</term2> 

       </item>

</List>

let $y :=

<List xmlns="http://www.mynamespace.com/report/1";>

       <item>

              <term1>d e f</term1> 

              <term2>key2</term2> 

       </item>

       <item>

              <term1>a b c</term1> 

              <term2>key1</term2> 

       </item>

       <item>

              <term1>j k l</term1> 

              <term2>key4</term2> 

       </item>

       <item>

              <term1>g h i.</term1> 

              <term2>key6</term2> 

       </item>

</List>

 

Regards,

 

From: [email protected] 
[mailto:[email protected]] On Behalf Of Danny Sokolsky
Sent: Friday, July 02, 2010 4:42 PM
To: General Mark Logic Developer Discussion
Subject: Re: [MarkLogic Dev General] fuzzy node comparison logic

 

You can try and do a deep-equal on the children elements and if at least ½ of 
them are true, then return true.  Something like:

 

xquery version "1.0-ml";

let $x := <List xmlns="http://www.mynamespace.com/report/1";>

       <item>

              <term1>a b c</term1> 

              <term2>key1</term2> 

       </item>

       <item>

              <term1>d e f</term1> 

              <term2>key2</term2> 

       </item>

       <item>

              <term1>g h i.</term1> 

              <term2>key3</term2> 

       </item>

       <item>

              <term1>j k l</term1> 

              <term2>key4</term2> 

       </item>

       <item>

              <term1>m n o</term1> 

              <term2>key5</term2> 

       </item>

</List>

let $y :=

<List xmlns="http://www.mynamespace.com/report/1";>

       <item>

              <term1>a b c</term1> 

              <term2>key1</term2> 

       </item>

       <item>

              <term1>d e f</term1> 

              <term2>key2</term2> 

       </item>

       <item>

              <term1>g h i.</term1> 

              <term2>key6</term2> 

       </item>

       <item>

              <term1>j k l</term1> 

              <term2>key4</term2> 

       </item>

</List>

let $count := fn:count($x/node())

let $tf :=

  for $child at $i in $x/node()

  return

   if (fn:deep-equal($child, $y/element()[$i])) then 1 else 0

let $sum := fn:sum($tf)

return  

if (($count div $sum) ge .5) then fn:true() else fn:false()

 

-Danny

 

From: [email protected] 
[mailto:[email protected]] On Behalf Of Joshi, Utsav 
(LNG-CON)
Sent: Friday, July 02, 2010 1:25 PM
To: [email protected]
Subject: [MarkLogic Dev General] fuzzy node comparison logic

 

 

I want to compare node like below. Deep-equal will give me true or false (for 
below case, it will give false)

I want it to return me true if it matches more than 50% of item nodes (for 
below case, it is matching 3 item nodes so it should return me true)

 

Is there any way I can do that?

 

<List xmlns="http://www.mynamespace.com/report/1";>

       <item>

              <term1>a b c</term1> 

              <term2>key1</term2> 

       </item>

       <item>

              <term1>d e f</term1> 

              <term2>key2</term2> 

       </item>

       <item>

              <term1>g h i.</term1> 

              <term2>key3</term2> 

       </item>

       <item>

              <term1>j k l</term1> 

              <term2>key4</term2> 

       </item>

       <item>

              <term1>m n o</term1> 

              <term2>key5</term2> 

       </item>

</List>

 

<List xmlns="http://www.mynamespace.com/report/1";>

       <item>

              <term1>a b c</term1> 

              <term2>key1</term2> 

       </item>

       <item>

              <term1>d e f</term1> 

              <term2>key2</term2> 

       </item>

       <item>

              <term1>g h i.</term1> 

              <term2>key6</term2> 

       </item>

       <item>

              <term1>j k l</term1> 

              <term2>key4</term2> 

       </item>

</List>

 

Regards

 

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

Reply via email to