-1

How to get

I want to build a tags tree/graph that can make relationships like Pandas being within Python, and Data Science similar to Machine Learning. Aside from related tags, is there a way to do this?

Using the data explorer, is there a way to download a file of which tags appear frequently together in questions? Or see which tags are likely to be associated with the same user?

Is there a file download of tag hierarchies and synonyms or should I just webscrape the pages at https://stackoverflow.com/tags/synonyms?

4

3 Answers 3

2

You could leverage a PIVOT query to spot some relationships. This query does that:

select [tag row], [python], [pandas], [sql], [c++], [java], [javascript]

from (
select ptr.postid, trow.tagname [tag row], tcol.tagname [tag col] 
from posttags ptr
inner join tags trow 
   on trow.id = ptr.tagid
inner join posttags ptc 
   on ptr.postid = ptc.postid
inner join tags tcol on tcol.id = ptc.tagid
) data
pivot (
  count(postid)
  for [tag col] in ([python], [pandas], [sql], [c++], [java], [javascript])
) pvt
order by 4 desc 

An alternative might be looking at which tags go together on questions. Here is the query for # of questions with the same 5 tags

select t1.tagname
     , t2.tagname
     , t3.tagname
     , t4.tagname
     , t5.tagname
     , count(*) [post_cnt]
from (
select postid
     , [1] [tag1]
     , [2] [tag2]
     , [3] [tag3]
     , [4] [tag4]
     , [5] [tag5]
     , [6]
     , [7]
from (
select postid 
     , tagid
     , row_number() over (partition by postid order by tagid) [pos]
from posttags pm
) data
pivot (
   max(tagid)
   for [pos] in ([1], [2], [3], [4], [5], [6], [7])
) pvt
) tagpos
inner join tags t1 on t1.id = tag1
inner join tags t2 on t2.id = tag2
inner join tags t3 on t3.id = tag3
inner join tags t4 on t4.id = tag4
inner join tags t5 on t5.id = tag5
where [tag1] is not null 
and [tag2] is not null 
and [tag3] is not null 
and [tag4] is not null 
and [tag5] is not null 
group by  t1.tagname
     , t2.tagname
     , t3.tagname
     , t4.tagname
     , t5.tagname
     , [6], [7]
order by count(*) desc 

Keep in mind SEDE is updated once a week on Sunday.
Use the educational SEDE Tutorial written by the awesome Monica Cellio.
Say "Hi" in SEDE chat.

2
  • It's great. How do I pass in my own array? For example the top 50 tags?
    – Ben Hendel
    Commented Jan 2, 2023 at 23:23
  • @BenHendel just fork the query and edit. You don't need an account.
    – rene
    Commented Jan 2, 2023 at 23:37
1

You can always use SEDE to do this, but you will be building this query by yourself, for the most part.

0

There are not explicit data downloads of this sort, no.

A SEDE query like select count(*) from posts where posttypeid=1 and tags like '%python%' and tags like '%pandas%' can give you a number of posts with a specific pair of tags - but you could just as easily (and much faster!) use the site search if you just care about raw counts of results.

If you want to figure out many such values (like for all possible pairs of tags), good luck. You are almost certainly going to be writing a lot of external code and possibly making the company upset with your API use and/or page scraping.

That said, the names of valid tags are stored directly: select tagname from tags. The result of this query seems to be cached, but there are more than 50,000 valid tags and you will be limited to that many rows. It's presumably possible to cross-reference the Tags and PostTags tables and figure out how many questions use each tag, and focus on popular ones.

2
  • How would I run this query for every pair of tags in the top 50 tags?
    – Ben Hendel
    Commented Jan 2, 2023 at 22:20
  • Perhaps you could try writing a pair of nested loops in your favourite programming language? Or use something from that language's standard library to generate combinations (ordered pairs) of tags? Or doing research on Stack Overflow about that problem? Commented Jan 2, 2023 at 22:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .