input: Write a function to calculate the number of common substrings between two given strings. A substring is a contiguous sequence of characters within a string. The function should return an integer indicating the count of common substrings. If either of the strings is empty, the function should return 0.
  assert num_common_substrings("abcd", "bae")==1
  assert num_common_substrings("abc", "def")==0
  assert num_common_substrings("aaaa", "aa")==3
  assert num_common_substrings("", "abc")==0
  assert num_common_substrings("abc", "")==0
output: def num_common_substrings(s1, s2):
      if not s1 or not s2:
          return 0
      set1 = set()
      set2 = set()
      for i in range(len(s1)):
          for j in range(i + 1, len(s1) + 1):
              set1.add(s1[i:j])
      for i in range(len(s2)):
          for j in range(i + 1, len(s2) + 1):
              set2.add(s2[i:j])
      return len(set1 & set2)