Asked  7 Months ago    Answers:  5   Viewed   42 times

I have tables in my mySQL database like:

+-------+------------+-------------+-----------+
|  ID   |  subject   |  Predicate  |  object   |
+-------+------------+-------------+-----------+
|  1    | ATM        |  subClassof | Network   |
+-------+------------+-------------+-----------+
|  2    | ARPANET    |  subClassof | Network   |
+-------+------------+-------------+-----------+
|  3    | Network    |  subClassof | Main      |
+-------+------------+-------------+-----------+
|  5    | Software   |  subclassof | Main      |
+-------+------------+-------------+-----------+
|  7    | Linux      |  subClassof | Software  |
+-------+------------+-------------+-----------+
|  8    | Windows    |  subClassof | Software  |
+-------+------------+-------------+-----------+
|  12   | XP         |  subClassof | Windows   |
+-------+------------+-------------+-----------+
|  13   | Win7       |  subClassof | Windows   |
+-------+------------+-------------+-----------+
|  14   | Win8       |  subClassof | Windows   |
+-------+------------+-------------+-----------+

For Predicate subClassof it will have a tree view like this:

Main
   |__ Network
   |         |__ ATM
   |         |__ ARPANET
   |
   |__ Software
              |__ Linux
              |__ Windows
                        |__ XP
                        |__ Win7
                        |__ Win8

I want to create a form which can select the start node and get all parent for that. For example by choosing Win7 i want to get:

main, Software, Windows,Win7


Step2: is there any way to print this nodes with a simple text like this:

Main
   |__ Software
              |__ Windows
                        |__ Win7

 Answers

88

Your data can be represented in RDF as data.n3:

@prefix : <http://example.org/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

:Network rdfs:subClassOf :Main .

:ATM rdfs:subClassOf :Network .
:ARPANET rdfs:subClassOf :Network .

:Software rdfs:subClassOf :Main .

:Linux rdfs:subClassOf :Software .
:Windows rdfs:subClassOf :Software .

:XP rdfs:subClassOf :Windows .
:Win7 rdfs:subClassOf :Windows .
:Win8 rdfs:subClassOf :Windows .

From here, you just want a SPARQL query that finds all the things connected to a particular class by a path (including the empty path) of rdfs:subClassOf properties.

prefix : <http://example.org/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>

select ?superclass where { 
  :Win7 rdfs:subClassOf* ?superclass
}
--------------
| superclass |
==============
| :Win7      |
| :Windows   |
| :Software  |
| :Main      |
--------------

The results in that query aren't necessarily ordered by their position in the path (though in this case they happen to be). If you do need them in order, you can do this (which is based on this answer about computing the position of elements in an RDF list):

prefix : <http://example.org/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>

select ?class where { 
  :Win7 rdfs:subClassOf* ?mid .
  ?mid rdfs:subClassOf* ?class .
}
group by ?class
order by count(?mid)

This finds each ancestor ?class of :Win7 as well as each ?mid intermediate ancestor. For ancestor ?class, the distance is computed as the number of intermediate relations in between (count(?mid)). It orders the results based that distance, so :Win7 is the closest ancestor, :Windows after that, and so on.

You can even do some of the fancy formatting you want like this:

prefix : <http://example.org/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>

select (group_concat( ?name ; separator="--" )  as ?path) where {
  {
    select ?name where { 
      :Win7 rdfs:subClassOf* ?mid .
      ?mid rdfs:subClassOf* ?class .
      bind( strAfter( str(?class), "http://example.org/") as ?name )
    }
    group by ?class ?name
    order by count(?mid)
  }
}
-----------------------------------
| path                            |
===================================
| "Win7--Windows--Software--Main" |
-----------------------------------

It might be possible to do some fancier string processing and to get the multiline string. You might look at the latter part of this answer where there is some fancy formatting for a nicely aligned matrix for ideas.

Wednesday, March 31, 2021
 
Blacksonic
answered 7 Months ago
71

you can't print the result from mysqli_query, it is mysqli_resource and for dumping the error you need to change mysql_error() to mysqli_error()

$username = "bob";
$db = mysqli_connect("localhost", "username", "password", "user_data");
$sql1 = "select id from user_information where username='$username'";
$result = mysqli_query($db, $sql1) or die(mysqli_error());
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { 
    echo $row['id'].'<br>'; 
} 
Saturday, May 29, 2021
 
pamelus
answered 5 Months ago
52

You want to add a URI prefix to the front of a label string?

I think you might be confused about what URI prefixes do. They're just shorthand for full URIs, and aren't part of the URI, and they don't have any bearing on strings.

You can do something like what you want with

SELECT ?class (CONCAT("ex:", ?classLabel) AS ?label
WHERE {
   ?class rdf:type rdfs:Class.
   ?class rdfs:label ?classLabel.
}

But the prefix won't depend on the prefix of the URI.

You could have a chain of IF()s that tests the starting characters of STR(?class), but it will get ugly quickly:

BIND(IF(STRSTARTS(STR(?class), "http://example.com/"), "ex:", "other:") as ?prefix)

then

SELECT ... (CONCAT(?prefix, ?classLabel) AS ?label

There's almost certainly an easier way to get what you want than doing it in SPARQL though :)

Saturday, June 26, 2021
 
Besnik
answered 4 Months ago
39

yo need create the user "pma" in mysql or change this lines(user and password for mysql):

/* User for advanced features */
$cfg['Servers'][$i]['controluser'] = 'pma'; 
$cfg['Servers'][$i]['controlpass'] = '';

Linux: /etc/phpmyadmin/config.inc.php

Tuesday, July 13, 2021
 
ShadowZzz
answered 4 Months ago
13

memberOf (in AD) is stored as a list of distinguishedNames. Your filter needs to be something like:

(&(objectCategory=user)(memberOf=cn=MyCustomGroup,ou=ouOfGroup,dc=subdomain,dc=domain,dc=com))

If you don't yet have the distinguished name, you can search for it with:

(&(objectCategory=group)(cn=myCustomGroup))

and return the attribute distinguishedName. Case may matter.

Sunday, August 8, 2021
 
MDDY
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share